0

I'm developing a custom list sort of idea, which consists basically of usercontrols stacked vertically in a FlowLayoutPanel. I'm writing it this way so that I can add buttons that appear on the list item when it is selected.

The list item control has a few labels on it and some panels, so in order to determine whether the whole list item was clicked on (to select it, and make the buttons appear), I have to add click event handlers to all the labels and panels etc.

I was wondering if there was an easier way to do this, by capturing all the click events for the control, kinda like KeyPreview, but for click events.

Thanks.

2 Answers2

0

add a Rectangle over the top of the user controls and paint with a transparent brush then add the click handler to this.

Andrew

REA_ANDREW
  • 10,666
  • 8
  • 48
  • 71
0

I solved it eventually by overriding WndProc like so:

public partial class ListItem: UserControl
{
    private const int WM_MOUSEACTIVATE = 0x0021;

    protected override void WndProc(ref Message m)
    {
        if(m.Msg == WM_MOUSEACTIVATE)
        {
            Debug.Print("Activated!");
        }

        base.WndProc(ref m);
    }
}

I reckon this is probably the easiest solution. Still, thanks for the suggestions Andrew!