0
如何動態刪除/添加使用區域和圖形路徑類動態刪除/添加(取消刪除)表單區域在C#
如何動態刪除/添加使用區域和圖形路徑類動態刪除/添加(取消刪除)表單區域在C#
動態改變窗體的形狀(取消刪除)形式的區域,緊鄰將表單的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);
}
}
}
感謝您的回答。我想,一旦刪除,我無法回滾到原來的狀態。你的回答很直接 – 2010-04-04 09:15:52
@Suriyan:你真的應該把更多的精力投入到問你的問題,如果你希望有人能回答這個問題。 – 2010-04-03 12:51:43