2010-04-03 98 views

回答

0

動態改變窗體的形狀(取消刪除)形式的區域,緊鄰將表單的Region屬性設置爲從GraphicsPath創建的新對象Region。例如,上面有一個按鈕形式可以改變它的形狀是這樣的:(工作示例)

using System; 
using System.Drawing; 
using System.Drawing.Drawing2D; 
using System.Windows.Forms; 

namespace Sample 
{ 
    public class ShapedForm : Form 
    { 
     Button testbutton; 

     public ShapedForm() 
     { 
      // Create a button. 
      testbutton = new Button(); 
      testbutton.Location = new Point(10, 10); 
      testbutton.Size = new Size(50, 50); 
      testbutton.Text = "Click me!"; 
      testbutton.Click += new EventHandler(this.testbutton_Click); 
      this.Controls.Add(testbutton); 

      // Remove the border around the form. 
      this.FormBorderStyle = FormBorderStyle.None; 

      // Set the initial shape of the form to an ellipse. 
      GraphicsPath path = new GraphicsPath(); 
      path.AddEllipse(0, 0, 200, 100); 

      this.Region = new Region(path); 
     } 

     private void testbutton_Click(object sender, EventArgs e) 
     { 
      // Change the shape of the form to some other ellipse. 
      GraphicsPath path = new GraphicsPath(); 
      path.AddEllipse(0, 0, 100, 100); 
      path.AddEllipse(120, 40, 50, 50); 

      this.Region = new Region(path); 
     } 
    } 
} 
+0

感謝您的回答。我想,一旦刪除,我無法回滾到原來的狀態。你的回答很直接 – 2010-04-04 09:15:52