Moving a borderless form that contains child controls

  • Thread starter Thread starter Flyte
  • Start date Start date
F

Flyte

Hi all..

I have followed the directions outlined in http://msdn2.microsoft.com/
en-us/netframework/aa497373.aspx#7qgifyua
(search page for How do I support moving a borderless form?)

private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HTCAPTION = 0x2;

[ DllImport( "user32.dll" ) ]
public static extern bool ReleaseCapture();

[ DllImport( "user32.dll" ) ]
public static extern int SendMessage( IntPtr hWnd, int Msg, int
wParam, int lParam );

private void Form1_MouseDown( object sender, MouseEventArgs e )
{
if ( e.Button == MouseButtons.Left )
{
ReleaseCapture();
SendMessage( Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0 );
}
}

to move a borderless form, but what I am seeing is that this solution
only works for clicking
on the form, but not on a child control. For example, if I have a form
that contains a group
box that covers most of the form, then the above solution only works
for the area that the
group box doesn't cover.

Is there an easy way to implement this move regardless if the user
clicked on the form or a
control?

I am using a base form that all of my dialogs inherit from. I have
implemented the above code
on my base class.

Any help would be appreciated.
 
Hello Flyte,
private void Form1_MouseDown( object sender, MouseEventArgs e )
{
....
}
Is there an easy way to implement this move regardless if the user
clicked on the form or a control?

It should be easily possible by handling more than just the
Form1_MouseDown event above - just handle the MouseDown events for the
controls as well and do the same thing as you do for the form.


Oliver Sturm
 
Back
Top