2012-05-20 8 views
10

मैं प्रपत्र बनाने के लिए इस कोड का उपयोग कर रहा कोई सीमा शैली है।सी # में गोलाकार सीमाओं के साथ फार्म?</p> <pre><code>this.FormBorderStyle = FormBorderStyle.None; </code></pre> <p>मैं फार्म पर गोल किनारों बनाने की जरूरत है:

क्या कोई आसान तरीका है? मैं यह कैसे करुं?

+0

इस प्रश्न का उत्तर सहायक हो सकता है: http://stackoverflow.com/questions/5092216/c-sharp-form-with-custom-border-and-rounded-edges –

+0

यह शानदार लग रहा है, लेकिन उम। ..मैं नया हूं इसलिए ... मुझे नहीं पता कि यह सब सामान कहां रखा जाए। मुझे पता है कि कोड() चीज़ के तहत कोड कहां रखना है, लेकिन दूसरा मुश्किल है। क्या आप मेरी मदद कर सकते हैं? –

उत्तर

2

इस पर एक नज़र डालें: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.region.aspx

फार्म वर्ग नियंत्रण वर्ग से विरासत, इसलिए एक ही नमूना आप फार्म के क्षेत्र संपत्ति के लिए लिंक पर है कि कर की कोशिश (और फार्म पर कर निश्चित रूप से घटना):

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

कृपया संदर्भ प्रदान करें कि यह ओपी की समस्या क्यों हल करता है; कोड को शब्दों के लिए कभी भी प्रतिस्थापित नहीं करना चाहिए! इसके अलावा, [इसलिए] में योगदान के लिए धन्यवाद। – jpaugh

1

मैं जानता हूँ कि सवाल पहले से ही उत्तर था, मैं एक वैकल्पिक और मूर्खतापूर्ण लेकिन एक बहुत की सलाह नहीं दी अभ्यास जोड़ने के लिए के बाद से आपके प्रश्न का उत्तर को सीमित नहीं करता चाहते हैं कोड अस्तित्व में ...

  • भरने के रूप में अपने पृष्ठभूमि रंग के साथ एक खाली, वर्ग छवि बनाएं, फिर ऊपर-बाईं ओर गोलाकार कोनों को मिटा न देना, हर कोने को यह दोहराने
  • एक बहुत संभावना नहीं रंग सेट के रूप में अपने फार्म पृष्ठभूमि रंग
  • सेट अपने फार्म पर TransparencyKey के रूप में इस रंग
  • PictureBox के रूप में छवियों को जोड़ें और उन्हें इसी कोनों के लिए रखा

विओला!

संबंधित मुद्दे