Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Using C# and VS2010,

I try to create a user control which inherits from a PictureBox, lets call it NewPicBox. I have declared it in a new file under the project.

I have added to the NewPicBox designer a ContextMenuStri,
Should i add to the NewPicBox designer a regular PictureBox in order to have the PictureBox functionality?

I then want to place NewPicBox on a form,

Can i do that like placing a regular PictureBox if so how? i cant see it on the designer? should i do it dynamically, how?


I also want to handle the event of user pressing the NewPicBox with the mouse.

In order to handle the mouse event Should I declare the MouseUp as new?
(new protected void MouseUp(object sender, MouseEventArgs e)

Is there another way to handle those events?
Thanks!

What I have tried:

Creating the NewPicBox By right click on Projects' name Add->New Item...->Custom Control
and changing the inheritance from Control to PictueBox
Posted
Updated 8-Mar-18 2:54am

Deriving your control from PictureBox is the right way to go. At that point, you can override any method or event handler that your heart desires.
 
Share this answer
 
Comments
dj4400 8-Mar-18 10:07am    
I failed to override MouseMove for example
(with new it compiled but as i mentioned in my question i couldnt undestand how to place the NewPictureBox on the Form)
Ralf Meier 9-Mar-18 3:25am    
You could not override MouseMove ... but you could override the method 'OnMouseMove' - each Event has an corresponding On...-method. Now you can do what you like with the MouseMove. If you don't call the OnMouseMove from the base-class (at the end) it causes that the Event isn't fired (if you like).
As John has said, deriving your control from PictureBox is the way to go, but it's not as simple as changing the base class from a UserControl to a PictureBox - that will throw up errors which will probably stop the designer working with your control.
See here: How to: Inherit from Existing Windows Forms Controls | Microsoft Docs[^] which explains the steps you will need to take, and here: Customizing the PictureBox Control[^] for an example.
 
Share this answer
 
v2
Comments
dj4400 20-Mar-18 9:08am    
Thanks i will check these articles

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900