27
2012
03

BorderStyle设成none的窗体的移动

public partial class Form1 : Form
{
private bool isMouseDown = false;
private Point oldMouse;
public Form1()
{
InitializeComponent();
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
this.Top = this.Top + e.Y - oldMouse.Y;
this.Left = this.Left + e.X - oldMouse.X;
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
oldMouse.X = e.X;
oldMouse.Y = e.Y;
isMouseDown = true;
}
}

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}

private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
« 上一篇下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。