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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:26:49+00:00 2026-06-06T17:26:49+00:00

I have two Forms. One with where all the main code is being executed.

  • 0

I have two Forms. One with where all the main code is being executed. And the other form is displayed when clicking a menu item by using this method:

Form2 videoSettings = new Form2();       

private void videoToolStripMenuItem_Click(object sender, EventArgs e)
{
    videoSettings.Show();
}

The form which is then opened containsfields where the user gets to set some settings for the application.
enter image description here
Then when clicking the “save” button I want this variable: public int deviceIndex;
to be fetched from the original Form.

So I’m wondering if I can add any event or something in Form1 which detects when the save button is clicked in videoSettings (Form2)?

  • 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-06T17:26:51+00:00Added an answer on June 6, 2026 at 5:26 pm

    I would do it a different way. I’d separate the code between the UI handling and the business logic layers. So your scenario would run in such a way:

    1. The first form issues an event notifying that the button with certain semantics has been activated. The data needed for the processing is included into the event’s data.
    2. The business logic listens to this event, and decides to issue a command on the second form. It calls an appropriate method on the form’s class, passing the needed information as a parameter (and maybe preprocessing the parameter if needed).
    3. The second form receives the command from the business logic and updates the view.

    This way the problem doesn’t arise at all.


    Example: (I’m not the winforms expert, beware it can be totally wrong from the POV of best winforms practices.)

    Part 1 (first form):

    class ProcessingActivatedEventArgs : EventArgs
    {
        public ProcessingActivatedEventArgs(int data) { MoreData = data; }
        public int MoreData { get; protected set; }
    }
    
    class Form1 : Form
    {
        private int currentData;
        public event EventHandler<ProcessingActivatedEventArgs> ProcessingActivated;
        void OnButtonClick(object sender, EventArgs args)
        {
            // ...
            if (ProcessingActivated != null)
                ProcessingActivated(new ProcessingActivatedEventArgs(currentData));
        }
    }
    

    Part 2: (business logic)

    class Controller
    {
        Form1 f1;
        Form2 f2;
    
        void StartFirstForm()
        {
            f1 = new Form1();
            f1.ProcessingActivated += OnProcessingActivated;
            f1.Show();
        }
    
        void OnProcessingActivated(object sender, ProcessingActivatedEventArgs args)
        {
            int data = args.MoreData;
            f1.DisableProcessingRequests();
            model.ProcessingFinished += OnProcessingFinished;
            model.StartProcessing(data);
            if (data > 0)
                f2.DisplayDataProcessing(0, data);
            else if (data < 0)
                f2.DisplayDataProcessing(data, 0);
            else
                throw new SomeCoolException("impossible data");
        }
    }
    

    Part 3: (second form)

    class Form2 : Form
    {
        public void DisplayDataProcessing(int lower, int upper)
        {
            // ... update the UI
        }
    }
    

    Note that this implementation ties the Controller and forms tighter than it could be done. In WPF, the decoupling is achieved by using the appropriate DataContext (but I don’t know how to do it properly in WinForms).

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

Sidebar

Related Questions

I have two forms(one main form,and one submain form).I'd like to do something like
I (currently) have two forms, one that needs to call the other. In other
I have created two forms in my Windows Application. One Form acts as a
I'm using the jQuery Validation JS I have two contact forms, the main one
I have an application that consists of two forms. One form displays data returned
Hey all i have two JFrames one is my main login frame, user enters
I have two forms on one page and want to have the input boxes
I have two forms, one with a radio button that users must select to
I have two forms. First one is to decide button numbers by using jslider.
How can two forms share the same inputs? I have two forms, one for

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.