Basically, I have a form that I can move with a mouse click Mouse_Down
, and this form has a label in the middle displaying some text. The problem is that when the click occurs within the label frame, the form doesn't move, and when I disable the label, the form does move however the text colour is changed to black, when it's supposed to be white.

- 147
- 2
- 13
2 Answers
There are two solutions:
1.
Write a message preprocess method by overriding the Control.PreProcessMessage
of your form. In this method, you have to deal with Windows messages, which is not hard to do, but you have to get used to it. pinvoke.net can help a lot here.
2.
Add a MouseDown
event handler to all of the controls in your form, like so:
foreach( Control control in this.Controls )
{
control.MouseDown += myMouseDownHandler;
}
myMouseDownHandler
will essentially be the same method that you use for the form itself.
If your form contains nested controls, like in a panel, or a user form, you will have to extent the loop, so that it also processes child controls of the form's controls.
If the only control in your form is this laben, then of course you don't need a loop.

- 2,009
- 2
- 31
- 63

- 1,610
- 11
- 24
-
[This](http://stackoverflow.com/a/11043661/815938) is an example of the first approach. – kennyzx Apr 09 '17 at 05:58
This is the standard code I use (when I have a borderless form):
using System.Runtime.InteropServices;
..
public const int WM_NCLBUTTONDOWN = 0xA1;
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();
private void YourLabel_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
I think it fakes having hit the Form's caption bar.
Of course you can hook up MouseDown
events from any number of other controls including the form to this same code.

- 53,122
- 8
- 69
- 111