Paul Matthews
Paul Matthews

Reputation: 2214

Child form not catching any mouse events

I have a windows forms application in which I instantiate another form (from the main form) and call it's Show() method. For some reason I am unable to receive any mouse events on the child form (there are no controls on it). Mouse events work fine on the parent form (in the area with no controls).

However, I can get mouse events to work on the child form if I override the base class method.

protected override void OnMouseDown(MouseEventArgs e)
    {
        // This works fine
    }

This seems totally wrong. What is happening that I'm missing?

Upvotes: 0

Views: 84

Answers (1)

Paul Matthews
Paul Matthews

Reputation: 2214

I finally figured it out. I created a custom constructor for the child form. It didn't call the InitializeComponent() method that you see in the normal constructor. Frankly I have no idea what the initializeComponent method does, but I do know that it wont let you have any mouse events. Although this is kinda stupid I hope that it might save somebody else a headache.

I should have chained my overloaded constructors like this:

public ChildForm(... params ...) : this()
{
    // code here...
}

Upvotes: 0

Related Questions