2012-05-20 31 views
10

Estoy usando este código para hacer que el formulario no tienen estilo de borde:¿Forma con bordes redondeados en C#?

this.FormBorderStyle = FormBorderStyle.None; 

Necesito hacer bordes redondeados en el formulario.

¿Hay alguna manera fácil? ¿Cómo lo hago?

+0

La respuesta a esta pregunta podría ser útil: http://stackoverflow.com/questions/5092216/c-sharp-form-with-custom-border-and-rounded-edges –

+0

Eso se ve muy bien, pero um. .. soy nuevo así que ... no tengo idea de dónde poner todas esas cosas. Sé dónde poner el código bajo la forma(), pero el otro es difícil. ¿Me puedes ayudar? –

Respuesta

2

Tome un vistazo a esto: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.region.aspx

La clase Form hereda de la clase de control, a fin de tratar de hacer la misma muestra que usted tiene en el enlace a la Región de propiedades del formulario (y hacerlo en la forma caso, por supuesto):

// This method will change the square button to a circular button by 
// creating a new circle-shaped GraphicsPath object and setting it 
// to the RoundButton objects region. 
private void roundButton_Paint(object sender, 
    System.Windows.Forms.PaintEventArgs e) 
{ 

    System.Drawing.Drawing2D.GraphicsPath buttonPath = 
     new System.Drawing.Drawing2D.GraphicsPath(); 

    // Set a new rectangle to the same size as the button's 
    // ClientRectangle property. 
    System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle; 

    // Decrease the size of the rectangle. 
    newRectangle.Inflate(-10, -10); 

    // Draw the button's border. 
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle); 

    // Increase the size of the rectangle to include the border. 
    newRectangle.Inflate(1, 1); 

    // Create a circle within the new rectangle. 
    buttonPath.AddEllipse(newRectangle); 

    // Set the button's Region property to the newly created 
    // circle region. 
    roundButton.Region = new System.Drawing.Region(buttonPath); 

} 
0
public static void RoundBorderForm(Form frm) 
    { 

     Rectangle Bounds = new Rectangle(0, 0, frm.Width, frm.Height); 
     int CornerRadius = 20; 
     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); 
     path.AddArc(Bounds.X, Bounds.Y, CornerRadius, CornerRadius, 180, 90); 
     path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y, CornerRadius, CornerRadius, 270, 90); 
     path.AddArc(Bounds.X + Bounds.Width - CornerRadius, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); 
     path.AddArc(Bounds.X, Bounds.Y + Bounds.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); 
     path.CloseAllFigures(); 

     frm.Region = new Region(path); 
     frm.Show(); 
    } 
+2

Proporcione el contexto de por qué esto resuelve el problema del OP; ¡El código nunca debe sustituir a las palabras! Además, gracias por contribuir a [so]. – jpaugh

1

sé que la pregunta ya fue contestada, me gustaría añadir una alternativa y tonto, pero no una práctica muy recomendable ya que su pregunta no restringe la respuesta a la existencia de códigos ...

  • crear una imagen en blanco, cuadrado con el color de fondo como de relleno, y luego borrar las esquinas redondeadas superior izquierda de ser transparente, repetir esto a todos los rincones
  • Establecer un color muy poco probable como su forma color de fondo
  • Conjunto de color como el TransparencyKey en su forma
  • añadir las imágenes como PictureBox y los pusieron a las esquinas correspondientes

Viola!

Cuestiones relacionadas