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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:33:20+00:00 2026-05-31T05:33:20+00:00

I have two projects in this solution: ProjectA and ProjectB. ProjectA is the main

  • 0

I have two projects in this solution: ProjectA and ProjectB. ProjectA is the main start-up project, and has a reference to ProjectB.

ProjectA has a file called MainForm.cs, which contains a textbox and the main UI.

ProjectB has a class inside Shapes.cs, containing a particular structure we’re using. Shapes.cs contains an event that is fired when the user changes some text for that object.

What I need to do is catch that text and set a textbox in MainForm.cs to that text. Is there a way we can do that? Basically I don’t see any reference to the main form inside Shapes.cs. I would like to do something like this:

( Shape1.Parent as MainForm ).TextBox1.Text = Shape1.Name;

, assuming the user types a string that gets stored in Shape1.Name. I need to escalate it to the main form.

I have searched around for other questions, and the closest lead I found was Matt Hamsmith’s answer on this question. But if it is a good approach I should follow, I do not know how to assign an event handler in the main form to an event in the separate class. I would appreciate any help.

Thanks.

  • 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-31T05:33:20+00:00Added an answer on May 31, 2026 at 5:33 am

    If the form is made up child controls, it should be listening to events on those controls, rather than the controls trying to cast their parent as a particular type. Doing that means your control will only ever work on that Form. It breaks encapsulation.

    Listen to an event like this:

    public class MainForm : Form
    {
        Shape _shape1 = new Shape();
    
        public MainForm()
        {
            InitializeComponent();
            _shape.ShapeNameChanged += HandleShapeNameChanged;
        }
    
        public void HandleShapeNameChanged(object sender, ShapeChangeEventArgs e)
        {
            textBox1.Text = e.NewName;
        }
    }
    
    public class Shape
    {
        public event EventHandler<ShapNameChangedEventArgs> ShapeNameChanged;
    }
    

    I’ve left it for you to:

    1. Define the ShapeNameChangedEventArgs object to contain whatever state you want it to.
    2. Invoke the event when something on your control changes.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My C# WinForms solution has two projects. A DLL which is the main project
I have two projects, the DLL project which has all my logic and data
I have two projects in my Solution. One implements my business logic and has
I have two projects in my solution   1- asp.net web project.   2-
I have a solution with two executable projects. Main.exe is dependent on Subordinate.exe .
I have two projects, Main and Core . I have a package called com.package.Sample
I have two projects: A/B. Project A is the project that contains all of
We have two projects that are both class libraries. Project 1 is a VS
I have a Project Collection setup in my TFS2010RC deployment. I have two Projects
I have two projects in my Visual Studio solution: The one is a WcfService

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.