Clicking on a label''s border does not work

Hey guys,

I've been trying to figure this out for a while now. I have a form with some labels. The labels' click events are handled fine if I click inside the label but if I position the mouse directly on the border of the label (a fixed single border) the click isn't registered.

Is it just impossible to click/double click the label's border and set off the click event handler? If anyone knows how this can be done, please let me know.

Thanks.

[457 byte] By [Flack] at [2008-1-7]
# 1

I subclassed a label and put code in the WndProc method to see what is going on. Apparently, when you add a border (fixed single) to a label, the client area starts 1 pixel in from the left and top edges, meaning, the top and left borders are excluded (the bottom and right borders are included). So, when you move the mouse over the left or top border of the label, the relative mouse coordinates are registered at -1.

I noticed that even though most mouse-type events weren't being generated when doing things over/on the top or left borders, I did see that the WM_NCHITTEST message was coming through. Out of curiousity, I indicated the result of the hit-test was that it hit in the control's client area... and all the sudden it recognized mouse movement and mouse clicks on the borders. I'm not sure if you want to get into subclassing for your particular application, but if you do, below is the WndProc code I had that appeared to be working:

Code Snippet

protected override void WndProc(ref System.Windows.Forms.Message m)

{

base.WndProc(ref m);

switch( m.Msg )

{

case 0x84: // WM_NCHITTEST

{

m.Result = new IntPtr(1); // HTCLIENT

}break;

default:

break;

};

}

ARK88 at 2007-10-2 > top of Msdn Tech,Windows Forms,Windows Forms General...