Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!