Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Moving a Form by clicking anywhere Using Interop and C#

Author: DevASP
Download Source Code : 456_movewindow.zip

In this article i will try to explain you, how you can move the form by clicking anywhere on it using InteropServices and C#.

Create new application Using C#. and Drag a label on it. Include the following namespace:

using System.Runtime.InteropServices;

Now add the following constants and Dll functions

public const int WM_NCLBUTTONDOWN = 0xA1;

 

private System.Windows.Forms.Label label1;

 

public const int HT_CAPTION = 0x2;

 

[DllImportAttribute ("user32.dll")]

 

public static extern int SendMessage(IntPtr hWnd,

 

int Msg, int wParam, int lParam);

           

[DllImportAttribute ("user32.dll")]

 

public static extern bool ReleaseCapture();

Now write the following code on from's mouse down event:

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

            {

                  if (e.Button == MouseButtons.Left)

                  {

                        ReleaseCapture();

                       

SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);

                  }

            }

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with Images in C# (Part 1)

Disclaimer - Privacy
© 2002-2017 DevASP.net