I am writing a usercontrol (winforms) which accept images from clipboard, do some manipulations and then allow user to upload it and get back URL of image.
I want user of that control to write his/her own code to upload. I have a Upload button in usercontrol, i want to call user written code on click of that button and pass image object.
I have tried with delegates but with delegate, user have to invoke it.
But i want user should not invoke it, instead it should be called on click of upload button in my control.
I have read following but they didn’t help
Pass Method as Parameter using C#
How can I pass a method name to another method and call it via a delegate variable?
Is there any way i can allow user to overwrite upload method in the form where control is being used, so he can write his own code or something else?
Can someone point me to right direction?
You have two main options for achieving this, either by requiring the user of the control to provide an upload method that is called by your control when the Upload button is clicked, or you can require that the control is sub-classed, and the
Uploadmethod implemented.Method 1 – Providing a delegate to be called upon upload:
Method 2 – Require the upload method to be overridden:
For the latter option, a user would need to sub-class the control before being able to use it, as follows: