我在VS C# 2008添加了 DotNetBar的RibbonBar 控件,想让界面更美观些,就把窗体改成了无边框的,可是这样就不能移动啦
想通过移动RibbonBar 控件来移动整个窗体
网上找到了很多版本的方法都不行,点在空白窗体处也移动不了
例如
private Point mouseOffset;
private bool isMouseDown = false;private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int xOffset;
int yOffset; if (e.Button == MouseButtons.Left)
{
xOffset = -e.X /*- SystemInformation.FrameBorderSize.Width*/;
yOffset = -e.Y /*- SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height*/;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
另一种
using System.Runtime.InteropServices;[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);
}问题出在哪里啊,这代码应该没问题吖
想通过移动RibbonBar 控件来移动整个窗体
网上找到了很多版本的方法都不行,点在空白窗体处也移动不了
例如
private Point mouseOffset;
private bool isMouseDown = false;private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int xOffset;
int yOffset; if (e.Button == MouseButtons.Left)
{
xOffset = -e.X /*- SystemInformation.FrameBorderSize.Width*/;
yOffset = -e.Y /*- SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height*/;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
另一种
using System.Runtime.InteropServices;[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);
}问题出在哪里啊,这代码应该没问题吖
解决方案 »
- [报价系统跟ERP]真诚合作 互相学习 共同提高
- 如何验证SQL数据库是否存在某登录名和密码?
- 20090811新手求助?
- 窗体上的状态栏控件和工具栏控件(急啊!)
- 在C#应用程序中,添加web引用,出现自定义工具警告: DiscoCodeGenerator 无法初始化代码生成器,没有生成任何代码.向Form添加Dataset时,找
- xml文件如何部分读取和保存
- 如何把form1的textbox里的值传给form2的listbox的items里面?在线急等!
- 向高手咨询有关console程序的问题
- 老大们帮忙呀,访问器的问题,如何在访问器中使用数组?
- 关于控件问题
- 我要枚举一些十六进制的数据,请问怎样枚举出来?
- VS2005连接不上SQL2008,为什么?
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
}
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); }
那怪了我可以移动啊
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
} 代码是没问题的
你窗体里面的控件是不是把form1给占用完了? 导致你怎么点也点不到form1上只能点击到别的控件上,建议在窗体上面加一个panel然后用panel_MouseDown事件,这个panel可以设置背景色为透明
private Point mouseOffset;
private bool isMouseDown = false;//这两行全局! private void Form1_MouseDown(object sender, MouseEventArgs e)//自己在Form1事件里点,然后粘代码!
{
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight -
SystemInformation.FrameBorderSize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
} } private void Form1_MouseMove(object sender, MouseEventArgs e)//自己在Form1事件里点,然后粘代码! {
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
} private void Form1_MouseUp(object sender, MouseEventArgs e)//自己在Form1事件里点,然后粘代码! {
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
} }
我行的。楼主试试?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace Invoicing_Tube
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
//定义一下坐标
private Point mouseOffset;
//判断一下是否按下了左键默认的为False
private bool isMouseDown = false;
private void login_MouseDown(object sender, MouseEventArgs e)
{
try
{
//X轴
int xOffset;
//Y轴
int yOffset;
//当按下左键时
if (e.Button == MouseButtons.Left)
{
//X轴为当前的位置加上窗体的长度
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
//Y轴为当前的位置加上窗体的高度
yOffset = -e.Y - SystemInformation.CaptionHeight -
SystemInformation.FrameBorderSize.Height;
//综合一下坐标
mouseOffset = new Point(xOffset, yOffset);
//表示按下了左键
isMouseDown = true;
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString(), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
} private void login_MouseMove(object sender, MouseEventArgs e)
{
try
{
//如果按下了左键
if (isMouseDown)
{
//前当的坐标==鼠标的位置
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString(), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
} private void login_MouseUp(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message.ToString(), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}