效果
实现方式
1、创建窗体,把窗体是属性FormBorderStyle设置为None即可去除窗体的边框。
2、设置当鼠标按下和鼠标移动时的事件
3、计算鼠标移动位置
int oldX, oldY;
//鼠标按下
private void DxLogin_MouseDown(object sender, MouseEventArgs e)
{
//判断是否为鼠标左键
if (e.Button == MouseButtons.Left)
{
//获取鼠标左键按下时的位置
this.oldX = e.Location.X;
this.oldY = e.Location.Y;
}
}
//鼠标移动
private void DxLogin_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//计算鼠标移动距离
this.Left += e.Location.X-this.oldX;
this.Top += e.Location.Y - this.oldY;
}
}