1. 程式人生 > >新手小白適合、關於C#不規則窗體的移動寫法

新手小白適合、關於C#不規則窗體的移動寫法

c# event 適合 his 記錄 pri epo com main

public partial class FrmMain : Form
{
Point old;//新建一個Point對象用來記錄窗體原坐標
public FrmMain()
{
InitializeComponent();
}

///鼠標的單擊事件

private void FrmMain_MouseDown(object sender, MouseEventArgs e)
{
old = new Point(-e.X, -e.Y);//記錄窗體的原位置
}

///鼠標的移動事件

private void FrmMain_MouseMove(object sender, MouseEventArgs e)//參數e為鼠標的事件參數
{

//判斷鼠標是否按得是左鍵
if (e.Button == MouseButtons.Left)//e為參數
{
//記錄鼠標的當前位置
Point newP = MousePosition;
newP.Offset(old);//平移
this.Location = newP;//改變當前窗體的位置
}
}

新手小白適合、關於C#不規則窗體的移動寫法