Welcome

首页 / 软件开发 / .NET编程技术 / 如何通过鼠标控制无标头窗体

如何通过鼠标控制无标头窗体2012-01-16 csdn博客 jinjazz这个问题也是来自论坛提问,同样是.Net WinForm新手的问题,这样的问题如果在Deplphi这样的板块立刻就被秒杀了,可是.Net版知道的人好像不太多。

介绍两个方法,一个是发送SC_Move消息,一个是改变鼠标区域消息

方法一:

1.usingSystem;
2.usingSystem.Collections.Generic;
3.usingSystem.ComponentModel;
4.usingSystem.Data;
5.usingSystem.Drawing;
6.usingSystem.Text;
7.usingSystem.Windows.Forms;
8.usingSystem.Runtime.InteropServices;
9.namespaceWindowsApplication1
10.{
11. publicpartialclassForm1 : Form
12.{
13. publicForm1()
14.{
15.InitializeComponent();
16.}
17.[DllImport( "user32.dll" , EntryPoint ="SendMessage" )]
18. public static extern intSendMessage( inthWnd,intwMsg,intwParam,intlParam);
19.[DllImport( "user32.dll" , EntryPoint ="ReleaseCapture" )]
20. public static extern intReleaseCapture();
21. public const intWM_SysCommand = 0x0112;
22. public const intSC_MOVE = 0xF012;
23.
24.
25. private voidForm1_MouseDown( objectsender, MouseEventArgs e)
26.{
27.ReleaseCapture();
28.SendMessage( this .Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);
29.}
30.
31. private voidForm1_Load( objectsender, EventArgs e)
32.{
33.
34.}
35.}
36.}
方法二:

1.usingSystem;
2.usingSystem.Windows.Forms;
3.namespaceWindowsApplication1
4.{
5. publicpartialclassForm1 : Form
6.{
7. publicForm1()
8.{
9.InitializeComponent();
10.}
11.
12. protected override voidWndProc( refMessage m)
13.{
14. base .WndProc( refm);if(m.Msg == 0x84)
15.{
16. switch(m.Result.ToInt32())
17.{
18. case1:
19.
20.m.Result =newIntPtr(2);break ;
21.}
22.}
23.}
24.}
25.}