WPF无边框窗体怎么移动?C#
我想做一个WPF窗体,没有边框,怎么靠鼠标左键拖动窗体位置?不要API……是WPF窗体不是WinForm窗体,WPF的MouseEventArgs和WinForm的不一样...
我想做一个WPF窗体,没有边框,怎么靠鼠标左键拖动窗体位置?不要API……
是WPF窗体不是WinForm窗体,WPF的MouseEventArgs和WinForm的不一样,求用法 展开
是WPF窗体不是WinForm窗体,WPF的MouseEventArgs和WinForm的不一样,求用法 展开
4个回答
展开全部
不好意思,没看清提问,不要api的方法如下:
private bool leftFlag = false;
private Point mouseOff;
private void toolStrip2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
private void toolStrip2_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
Location = mouseSet;
}
}
private void toolStrip2_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false;
}
}
ps:这种方法很不好,鼠标移动快就会出问题
private bool leftFlag = false;
private Point mouseOff;
private void toolStrip2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
private void toolStrip2_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
Location = mouseSet;
}
}
private void toolStrip2_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false;
}
}
ps:这种方法很不好,鼠标移动快就会出问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-09-30
展开全部
[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;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{//拖动窗体
ReleaseCapture();
SendMessage(this.Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION, 0);
}
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;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{//拖动窗体
ReleaseCapture();
SendMessage(this.Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION, 0);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.DragMove();
}
{
this.DragMove();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是不是WindowStyle="None"?
如果是那就简单多了
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
如果是那就简单多了
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询