c# 如何实现窗体移动?
各位大侠,当没有边界时,怎么通过拖动窗体界面移动窗体,谢谢了!!!楼下的,你那个网址什么都没有阿...
各位大侠,当没有边界时,怎么通过拖动窗体界面移动窗体,谢谢了!!!
楼下的,你那个网址什么都没有阿 展开
楼下的,你那个网址什么都没有阿 展开
4个回答
展开全部
renzhijie99 正解,测试正确
鉴定完毕!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form6 : Form
{
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
public Form6()
{
InitializeComponent();
}
private void Form6_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
}
鉴定完毕!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form6 : Form
{
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
public Form6()
{
InitializeComponent();
}
private void Form6_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用3个事件,mouseMove mousedown mouseup
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.添加下列代码到你的窗体中:
#region 轻松移动
bool isInMove;
Point oldPoint;
void InitializeEasyMove()
{
isInMove = false;
this.MouseDown += new MouseEventHandler(EasyMove_MouseDown);
this.MouseUp += new MouseEventHandler(EasyMove_MouseUp);
this.MouseMove += new MouseEventHandler(EasyMove_MouseMove);
}
void EasyMove_MouseMove(object sender, MouseEventArgs e)
{
if (!isInMove) return;
Point pt = PointToScreen(e.Location);
if (pt.X == oldPoint.X || pt.Y == oldPoint.Y) return;
this.Location = new Point(this.Location.X + pt.X - oldPoint.X, this.Location.Y + pt.Y - oldPoint.Y);
oldPoint = pt;
}
void EasyMove_MouseUp(object sender, MouseEventArgs e)
{
isInMove = false;
}
void EasyMove_MouseDown(object sender, MouseEventArgs e)
{
isInMove = true;
oldPoint = PointToScreen(e.Location);
}
#endregion
2.在你的窗体的构造函数或Load事件中调用:
InitializeEasyMove();
#region 轻松移动
bool isInMove;
Point oldPoint;
void InitializeEasyMove()
{
isInMove = false;
this.MouseDown += new MouseEventHandler(EasyMove_MouseDown);
this.MouseUp += new MouseEventHandler(EasyMove_MouseUp);
this.MouseMove += new MouseEventHandler(EasyMove_MouseMove);
}
void EasyMove_MouseMove(object sender, MouseEventArgs e)
{
if (!isInMove) return;
Point pt = PointToScreen(e.Location);
if (pt.X == oldPoint.X || pt.Y == oldPoint.Y) return;
this.Location = new Point(this.Location.X + pt.X - oldPoint.X, this.Location.Y + pt.Y - oldPoint.Y);
oldPoint = pt;
}
void EasyMove_MouseUp(object sender, MouseEventArgs e)
{
isInMove = false;
}
void EasyMove_MouseDown(object sender, MouseEventArgs e)
{
isInMove = true;
oldPoint = PointToScreen(e.Location);
}
#endregion
2.在你的窗体的构造函数或Load事件中调用:
InitializeEasyMove();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询