Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
AutoSize no se ajusta a mi control de interfaz de usuario personalizado

Soy un principiante en diseño de interfaz de usuario y formularios de Windows en general. Y estoy encontrando algunos problemas al diseñar un control de control personalizado

El problema que tengo es que los formularios de Windows no se ajustan correctamente a mi control

Así es como se ve:

ingrese la descripción de la imagen aquí

Incluso al deshabilitar AutoSize, todavía se ve mal.

Nuevamente, no tengo mucha experiencia y vi un tutorial para hacer este botón de cambio.

Como puede ver, los bordes del círculo están completamente cortados, y no sé por qué.

Aquí está el código:

 public AzTogglebutton() { this.AutoSize = true; this.MinimumSize = new Size(50, 22); } private GraphicsPath GetFigurePath() { int arcSize = this.Height - 1; Rectangle leftArc = new Rectangle(0, 0, arcSize, arcSize); Rectangle rightArc = new Rectangle(this.Width - arcSize - 2, 0, arcSize, arcSize); GraphicsPath path = new GraphicsPath(); path.StartFigure(); path.AddArc(leftArc, 90, 180); path.AddArc(rightArc, 270, 180); path.CloseFigure(); return path; } protected override void OnPaint(PaintEventArgs pevent) { int toggleSize = this.Height + 3; pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias; pevent.Graphics.Clear(this.Parent.BackColor); if (this.Checked) //ON { //Draw the control surface if (solidStyle) pevent.Graphics.FillPath(new SolidBrush(onBackColor), GetFigurePath()); else pevent.Graphics.DrawPath(new Pen(onBackColor, 2), GetFigurePath()); //Draw the toggle pevent.Graphics.FillEllipse(new SolidBrush(onToggleColor), new Rectangle(this.Width - this.Height + - 2, -2, toggleSize, toggleSize)); } else //OFF { //Draw the control surface if (solidStyle) pevent.Graphics.FillPath(new SolidBrush(offBackColor), GetFigurePath()); else pevent.Graphics.DrawPath(new Pen(offBackColor, 2), GetFigurePath()); //Draw the toggle pevent.Graphics.FillEllipse(new SolidBrush(offToggleColor), new Rectangle(-2, -2, toggleSize, toggleSize)); } }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Hice algunos ajustes al tamaño que estás usando:

 private GraphicsPath GetFigurePath() { var arcSize = this.ClientSize.Height; var leftArc = new Rectangle(0, 0, arcSize, arcSize - 1); var rightArc = new Rectangle(this.ClientSize.Width - arcSize - 1, 0, arcSize, arcSize - 1); var path = new GraphicsPath(); path.StartFigure(); path.AddArc(leftArc, 90, 180); path.AddArc(rightArc, 270, 180); path.CloseFigure(); return path; }

Para mantener la coherencia, seguiría usando GraphicsPath para dibujar el círculo resaltado:

 private GraphicsPath GetOnPath() { var arcSize = this.ClientSize.Height; var leftArc = new Rectangle(0, 0, arcSize, arcSize - 1); var rightArc = new Rectangle(0, 0, arcSize, arcSize - 1); var path = new GraphicsPath(); path.StartFigure(); path.AddArc(leftArc, 90, 180); path.AddArc(rightArc, 270, 180); path.CloseFigure(); return path; }

El final resulto:

 pevent.Graphics.Clear(this.Parent.BackColor); pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias; pevent.Graphics.FillPath(new SolidBrush(offBackColor), GetFigurePath()); pevent.Graphics.FillPath(new SolidBrush(offToggleColor), GetOnPath());

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda