拖动窗体MOUSEUP怎么写,用什么方法?
拖动窗体MOUSEUP怎么写,用什么方法?
------解决方案--------------------拖动窗体MOUSEUP怎么写
-------
不明白你要的是什么?拖动窗体,是移动窗体,还是高速大小,还是都是.
为什么要写MouseUp事件,而不用MouseMove或MouseDown事件呢?
------解决方案--------------------//参考如下代码:
//客户区拖动窗体
[DllImport( "User32.DLL ")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int iParam);
[DllImport( "User32.DLL ")]
public static extern bool ReleaseCapture();
public const uint WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 61456;
public const int HTCAPTION = 2;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
}
------解决方案--------------------把如下代码粘入窗口试试:
internal static int WM_NCHITTEST = 0x84; //移动鼠标,按住或释放鼠标时发生的系统消息
internal static IntPtr HTCLIENT = (IntPtr)0x1;//工作区
internal static IntPtr HTCAPTION = (IntPtr)0x2; //标题栏
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if (m.Result == HTCLIENT)
{
m.HWnd = this.Handle;
System.Drawing.Rectangle rect = this.RectangleToScreen(this.ClientRectangle);
Point C_Pos = Cursor.Position;
m.Result = HTCAPTION;//模拟标题栏,移动或双击可以最大或最小化窗体
}
}
else if (m.Msg == 0xa3)
{
return;
}
else
{
base.WndProc(ref m);
}
}
------解决方案-------------------- <div id= 'calendar ' onMouseDown= 'catchCalendar(this) ' onMouseUp= 'releaseCalendar(this) '>
//******************************************* Move **********************************************************//
// 功能:让日历可移动
// 编码:Dragon Deng
var IsMove = false;
var dragClickX = 0;
var dragClickY = 0;
function catchCalendar(e){
IsMove = true;
dragClickX=event.clientX-parseInt(document.getElementById( "calendar ").style.left);
dragClickY=event.clientY-parseInt(document.getElementById( "calendar ").style.top);
document.getElementById( "calendar ").setCapture();
document.onmousemove = moveCalendar;
}
function releaseCalendar(e){
IsMove = false;
document.getElementById( "calendar ").releaseCapture();
document.onmousemove = null;
hideElement( 'SELECT ', document.getElementById( "calendar ") );
hideElement( 'APPLET ', document.getElementById( "calendar ") );
}
function moveCalendar(e){
if(IsMove){
document.getElementById( "calendar ").style.left =event.clientX-dragClickX;
document.getElementById( "calendar ").style.top = event.clientY-dragClickY;
document.getElementById( "calendar ").style.visible = 'show '
}
}
//
//******************************************* end ***********************************************************//
------解决方案--------------------private void Form1_MouseUp(object sender,System.Windows.Forms.MouseEventArg e)
{
int nX=e.x;
int nY=e.y;
this.Width=nX;
this.Height=nY;
}