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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:47:17+00:00 2026-05-21T08:47:17+00:00

I have a windows form1 application. This form1 has a click button. When the

  • 0

I have a windows form1 application. This form1 has a click button. When the button is clicked some events handler are created in the click-button method. In the SendText event handler method I a create and show a second Form2 where i want to print a string value met in form1.

The problem is the fact that in my ListBox I see just one string and not all of them (I am consecutively sending strings). Why? Plus there are no additional Form2 forms created and shown when a new event handler arrives.

In Form1 this is the way i am calling form2:

public void Send(string body, string name)
{
    Form2 form2 = new Form2(body);
    form2.Text = name;
    form2.ShowDialog ();
} 

public  void OnMessage(first val, second vall)
{
    send(string val1, string va2);
}

Form2 contains:

public Form2(string s)
{
    InitializeComponent();
    listBox1.Items.Add(s);
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}

2 Questions:

  1. How can i create multiple Form2 forms each time the handler is activated (using threads, no?)?

  2. If first val is the same when a new handler arrives how can I activate the form2 that is already on the screen and add a new item in the ListBox1?

Please provide examples, if possible.

Thank you.

  • 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-21T08:47:18+00:00Added an answer on May 21, 2026 at 8:47 am

    if i got this right, you want:

    • a new form2 for each unique “name” param in Send(…)
    • all following calls to Send(…) with the same param “name” should add the string in the “body” param to the same list on the associated form2

    what about this?

    Dictionary<string,From2> myForm2s = new Dictionary<string,Form2>();
    
    public void Send(string body, string name)
    {
       Form2 frm = null;
       if(!myForm2s.tryGetValue(name,out frm))
       {
          frm = new Form2(body);
          myForm2s[name] = frm;
          frm.Text = name;
          frm.FormClosing += new FormClosingEventHandler(Form2_FormClosing);
          frm.Show();
       }
       else
       {
          frm.listBox1.Items.Add(body); // assuming listBox1 is public
          frm.Show();
          frm.BringToFront();
       }
    }
    void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
       e.Cancel = true;
       ((Form2)sender).Hide();
    }
    

    (code not tested…)

    you will possibly want to handle the FormClosing event of Form2 … cancel the event using the eventarg and call this.Hide() … so a Form2 will still disappear if the user klicks the x but the form is still there, ready to be reshown when the next event adds something to it …

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

Sidebar

Related Questions

This is a Windows Forms application. I have a function which captures some mouse
I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I have a windows application which has 3 forms : Form1,2,3. I want to
I have created a dialog box in my WinForms application. This has many text
I have a C# Windows Form application that contains a menu with this event:
I am using C# with a Windows Application Form. In this I have a
I have a Windows Forms application that I wrote that does some monitoring of
I have done a global mouse event in my windows application. When i click
I have developed a Windows Forms application and it has a datagrid with checkbox.
I have a windows form application in which the Form1 object's initial WindowState ==

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.