2012-05-20 6 views
10

ich diesen Code bin mit der Form zu machen, haben keine Grenze Stil:Formular mit abgerundeten Rahmen in C#?

this.FormBorderStyle = FormBorderStyle.None; 

I abgerundete Kanten auf dem Formular vornehmen müssen.

Gibt es einen einfachen Weg? Wie mache ich es?

+0

Die Antwort auf diese Frage könnte hilfreich sein: http://stackoverflow.com/questions/5092216/c-sharp-form-with-custom-border-and-rounded-edges –

+0

Das sieht gut aus, aber ähm. ..ich bin neu so ... ich habe keine Ahnung wo ich all das Zeug hinkriege. Ich weiß, wo der Code unter der Form() Ding, aber der andere ist schwer. Kannst du mir helfen? –

Antwort

2

einen Blick auf diese: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.region.aspx

Die Form-Klasse von der Control-Klasse erbt, so versuchen, die gleiche Probe zu tun, dass Sie auf den Link, um die Eigenschaft Region Formular (und tun es auf dem Formular Veranstaltung natürlich):

// 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

Bitte erläutern Sie, warum dies das Problem des OPs löst. Code sollte niemals Wörter ersetzen! Danke auch für den Beitrag zu [so]. – jpaugh

1

ich die Frage wissen, wurde bereits beantwortet, würde ich mag eine Alternative und albern, aber eine nicht wirklich zu empfehlen Praxis hinzuzufügen, da Ihre Frage die Antwort nicht einschränken in sein Codes ...

  • Erstellen Sie ein leeres, quadratisches Bild mit Hintergrundfarbe als Füllung, löschen Sie dann die links oben abgerundeten Ecken transparent sein, wiederholen Sie diese an allen Ecken
  • eine sehr unwahrscheinlich Farbe Set wie Ihr Formular Hintergrundfarbe
  • Set diese Farbe als TransparencyKey auf dem Formular
  • die Bilder als PictureBox hinzufügen und sie an die entsprechenden Ecken setzen

Viola!