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 317873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:31:03+00:00 2026-05-12T08:31:03+00:00

I was just wondering if I’m doing this the correct way. I have 2

  • 0

I was just wondering if I’m doing this the correct way. I have 2 forms a parent form and a child form (options dialog). To change a property in my parent form from my child form I use code like this:

// Create an array of all rich textboxes on the parent form.
var controls = this.Owner.Controls.OfType<RichTextBox>();

foreach (var item in controls) {
    if (chkDetectUrls.Checked)
        ((RichTextBox)item).DetectUrls = true;
    else
        ((RichTextBox)item).DetectUrls = false;
}

I only have one RichTextBox on my form. It seems silly to have to loop through a array of 1 control. Is this the correct way to do it or is there an easier way?

  • 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-12T08:31:04+00:00Added an answer on May 12, 2026 at 8:31 am

    It’s not appropriate to change properties in a parent form at all. Instead, your child form should raise an event which the parent form listens for, and changes its own value accordingly.

    Manipulating the parent form from the child creates a two-way coupling – the parent form owns the child, but the child also has intimate knowledge and dependency on the parent form. Bubbling is the established solution to this, as it allows information to flow upwards (‘bubbling’) while avoiding any strict coupling.

    Here is the most basic example of eventing. It does not include passing specific information in the event (which is what you may need) but covers the concept.

    In your child form:

    //the event
    public event EventHandler SomethingHappened;
    
    protected virtual void OnSomethingHappened(EventArgs e)
    {
        //make sure we have someone subscribed to our event before we try to raise it
        if(this.SomethingHappened != null)
        {
            this.SomethingHappened(this, e);
        }
    }
    
    private void SomeMethod()
    {
        //call our method when we want to raise the event
        OnSomethingHappened(EventArgs.Empty);
    }
    

    And in your parent form:

    void OnInit(EventArgs e)
    {
        //attach a handler to the event
        myChildControl.SomethingHappened += new EventHandler(HandleSomethingHappened);
    }
    
    //gets called when the control raises its event
    private void HandleSomethingHappened(object sender, EventArgs e)
    {
        //set the properties here
    }
    

    As I said above, you probably need to pass some specific information in your event. There’s a few ways we can do this, but the simplest one is to create your own EventArgs class and your own delegate. It looks like you need to specify whether some value is set to true or false, so let’s use that:

    public class BooleanValueChangedEventArgs : EventArgs
    {
        public bool NewValue;
    
        public BooleanValueChangedEventArgs(bool value)
            : base()
        {
            this.NewValue = value;
        }
    }
    
    public delegate void HandleBooleanValueChange(object sender, BooleanValueChangedEventArgs e);
    

    We can change our event to use these new signatures:

    public event HandleBooleanValueChange SomethingHappened;
    

    And we pass our custom EventArgs object:

    bool checked = //get value
    OnSomethingHappened(new BooleanValueChangedEventArgs(checked));
    

    And we change our event handling in the parent accordingly:

    void OnInit(EventArgs e)
    {
        //attach a handler to the event
        myChildControl.SomethingHappened += new HandleBooleanValueChange(HandleSomethingHappened);
    }
    
    //gets called when the control raises its event
    private void HandleSomethingHappened(object sender, BooleanValueChangedEventArgs e)
    {
        //set the properties here
        bool value = e.NewValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering what the correct way of structuring statements like this is? @products =
Just wondering what the best way to access read only information form a Microsoft
Just wondering if there is a way around this (or if it is even
Just wondering if anyone knows of a way to change the panorama background image
Just wondering if this would be an acceptable way of terminating an object from
Just wondering if this is the most efficient method of doing this? is there
Just wondering how I do this, Im creating a class that will have my
just wondering if there is a way to reduce the amount of code needed
Just wondering the best way to replace in place matches on a string. value.replace(bob,
Just wondering if anyone can optimize this usortMonths() function to be better? Basically I

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.