Search code examples
c#imageformspictureboxonmouseclick

Overridng OnMouseClick of PictureBox as a member


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 ?


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.