tags:

views:

67

answers:

2

Hi,

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.

A: 

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
A Rectangle? As in a System.Drawing.Rectangle?
http://stackoverflow.com/questions/347439/custom-controls-in-c-winforms-mouse-event-question
REA_ANDREW
A: 

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!