Moving a borderless form that contains child controls

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.
 
O

Oliver Sturm

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top