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

  • Home
  • SEARCH
  • 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 197881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:53:27+00:00 2026-05-11T16:53:27+00:00

I always set the modifiers on my form to private ,I don’t like internal

  • 0

I always set the modifiers on my form to private,I don’t like internal nor public.

Till now I used to Invoke like this:

public string Addtext
{
    if(InvokeRequired)
    {
         Invoke((MethodInvoker)delegate
         {
             textbox.text = value;
         });
    }
    else
        textbox.text = value;
}

But adding such property for every member on my form is just not Object Orientated at all.

I want to create a function that will Invoke the parameter(action).I tried my best,but I failed – it requires the form members to be public or internal 🙁

    public void PerformActionOnForm(Action<FormMain> action)
    {
        var form = Form.ActiveForm as FormMain;
        object s = action.Clone();
        if (form != null)
        {
            form.PerformAction(action);
        }
    }

    public void PerformAction(Action<FormMain> action)
    {
        if (InvokeRequired)
            Invoke(action, this);
        else
            action(this);
    }

two problems in my code:

It requires the property I’d like to change to be != private 🙁

Doesn’t work if the form is not on focus.

  • 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-05-11T16:53:27+00:00Added an answer on May 11, 2026 at 4:53 pm

    In what way is adding properties for data that needs to be accessed or set outside of the scope of the form “not object oriented at all?” This is really your only option. Code in an anonymous delegate (or any delegate, for that matter) executes in the context in which it was declared. The only facility for getting around visibility issues is reflection, and that is big smelly code smell. Create your properties and use them as appropriate.

    As for your second option, I’m assuming that you want to execute this on your “main form”. You have two options here: assume that there is only one instance and keep that as a static property on the class, assigning it in the instance constructor.

    public partial class MainForm : Form
    {
        private static MainForm singletonInstance;
    
        public static MainForm SingletonInstance
        {
            get { return singletonInstance; }
        }
    
        public MainForm() : base()
        {
            InitializeComponent();
    
            singletonInstance = this;
        }
    }
    
    public void PerformActionOnForm(Action<FormMain> action)
    {
        var form = MainForm.SingletonInstance;
        // object s = action.Clone(); What was this for?
        if (form != null)
        {
            form.PerformAction(action);
        }
    }
    

    The other only works if all of your forms are properly “owned” and the only form with no owner is your main form. In that instance you could do this:

    public void PerformActionOnForm(Action<FormMain> action)
    {
        var form = Form.ActiveForm.TopLevelControl as FormMain;
        // object s = action.Clone(); What was this for?
        if (form != null)
        {
            form.PerformAction(action);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always think of xml like a set data structure. Ie: <class> <person>john</person> <person>sarah</person>
Why is the heap space always set to zero?? Why is stack space similarly
I always thought that LIMIT in a query selects only between numbers I set.
I remember Google says we should always use the latest API and set the
If you set the Content-Disposition header to attachment , this causes user-agents to always
I've attempted to set the tint of my UIToolbar in IB, but that always
I am unable to set my inbuilt database to update . It is always
I need to set up an amazon server. I always here setup ubuntu on
window.open() why window.open always pop up with IE , I set firefox is the
In WinForms, to set focus to a specific control, I always seem to wind

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.