现有一个Form
添加一个picturebox 设置为dock=fill
鼠标点击picturebox实现窗体的拖动该怎么做?
注意:
下面这个函数已经不管用了,因为picturebox已经覆盖了form
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (m.Result == (IntPtr)HTCLIENT)
{
m.Result = (IntPtr)HTCAPTION;
}
break;
default:
base.WndProc(ref m);
break;
}
}[/color]
添加一个picturebox 设置为dock=fill
鼠标点击picturebox实现窗体的拖动该怎么做?
注意:
下面这个函数已经不管用了,因为picturebox已经覆盖了form
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (m.Result == (IntPtr)HTCLIENT)
{
m.Result = (IntPtr)HTCAPTION;
}
break;
default:
base.WndProc(ref m);
break;
}
}[/color]
解决方案 »
- C#如何将类似“...ad=e5=9b=bd...”的UFT8码转换为汉字。见例子:
- [求助] C# 写程序下载ftp execl 文件
- window 服务访问映射网络驱动器
- 如何动态修改AxisAngleRotation里的角度值?
- 怎样使TextBox输入值后的值自动为空
- html 中<u>是什么意思?
- 批量执行
- 请问高手们:如何调用FoxMail并附加附件
- 再问一下,急!!!我在win2000上用C#+Access2000开发的应用程序,在98上该怎么安装?
- 急问???如何弹出打开文件对话框,选择要用的文件,读出文件数据,然后将文件数据写入access数据库中,请写详细代码!!!
- 有关控件的组合
- ImgaeList问题。
private bool isMouseDown = false; private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOffset = new Point(-e.X, -e.Y);
isMouseDown = true;
}
} private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
this.Location = mousePos;
}
} private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}
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 Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
public static extern int ReleaseCapture();
public const int WM_SysCommand = 0x0112;
public const int SC_MOVE = 0xF012;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SysCommand, SC_MOVE,0 );
}
}
}