Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8981865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:26:28+00:00 2026-06-15T20:26:28+00:00

I am writing a usercontrol (winforms) which accept images from clipboard, do some manipulations

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:26:29+00:00Added an answer on June 15, 2026 at 8:26 pm

    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 Upload method implemented.

    Method 1 – Providing a delegate to be called upon upload:

    public partial class MyControl
    {
        // Define a delegate that specifies the parameters that will be passed to the user-provided Upload method
        public delegate void DoUploadDelegate(... parameters ...);
    
        private readonly DoUploadDelegate _uploadDelegate;
    
        public MyControl(DoUploadDelegate uploadDelegate)
        {
            if (uploadDelegate == null)
            {
                throw new ArgumentException("Upload delegate must not be null", "uploadDelegate");
            }
            _uploadDelegate = uploadDelegate;
            InitializeComponent();
        }
    
        // ...
    
        // Upload button Click event handler
        public void UploadButtonClicked(object sender, EventArgs e)
        {
            // Call the user-provided upload handler delegate with the appropriate arguments
            _uploadDelegate(...);
        }
    }
    

    Method 2 – Require the upload method to be overridden:

    public abstract partial class MyControl
    {
        private readonly DoUploadDelegate _uploadDelegate;
    
        protected MyControl()
        {
            InitializeComponent();
        }
    
        // ...
    
        // The method that users of the control will need to implement
        protected abstract void DoUpload(... parameters ...);
    
        // Upload button Click event handler
        public void UploadButtonClicked(object sender, EventArgs e)
        {
            // Call the overridden upload handler with the appropriate arguments
            DoUpload(...);
        }
    }
    

    For the latter option, a user would need to sub-class the control before being able to use it, as follows:

    public class MyConcreteControl : MyControl
    {
        protected override void DoUpload(... parameters ...)
        {
            // User implements their own upload logic here...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a WinForms user control. My plan is to allow the caller to
I am writing a custom control deriving from UserControl . In it are some
Writing an app which takes the preview frames from camera does some transformation to
I am currently writing a user control with the MVVM pattern which has some
I'm writing a user control in WPF which is based on a ListBox. One
I am writing application that will add usercontrol when user clicks on client area
I'm writing my own UserControl which displays data in a ListBox. I want to
I'm writing a WPF user control which internally uses MVVM. In order to work
Let's start from the beginning: I'm writing an algorithm for a Silverlight application, which
This is what I'm trying to do: I'm writing a UserControl that I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.