Question

I currently have a matrix which contains a members of my class called furniture
In this Furniture i have a PictureBox member which i want to override it's OnMouseClick method
where do i do that ?
In the Furniture class code ?
What is the syntax for overriding such a member ?

Was it helpful?

Solution

If you mean overriding there is no other place to do then in your custom class:

Create a new MyPictureBox class, derived from original PictureBox.

Example:

public class MyPictureBox : PictureBox {

    public override void OnMouseClick(...)  {
       //...
    }

}

and after, naturally, use this object in your form:

Furniture.Controls.Add(new MyPictureBox ());

Don't know what is Furniture control really, so this is just theoretical example.

OTHER TIPS

If you only want to detect the clicks, you just need to add a handler for PictureBox.MouseDown

You can do this in the designer - find the picture box, check its properties and select the "Events" then type in a name for the MouseDown handler.

Note that this is different from actually overriding OnMouseClick, but I suspect you don't really want to do that...

What is your reason for wanting to override OnMouseClick?

Please see following code.

public class DerivedPictureBox: PictureBox
{
    protected override void OnMouseClick(MouseEventArgs e)
    {
        base.OnMouseClick(e);
    }
}

Whenever you use DerivedPictureBox in your application, it will execute this derived OnMouseClick method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top