Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# How do I have Form1 send data to other forms

Posted on 2012-03-12
3
Medium Priority
?
277 Views
Last Modified: 2012-03-30
Form1 creates multiple instances of Form2
Button1 on Form1 populates a textbox on Form2 but not every instance - just one or two of them depending on the situation.
How do I do this?
0
Comment
Question by:pdering
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37713085
The same way as was described in your other question:  http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27629120.html
0
 
LVL 3

Accepted Solution

by:
pradhanv earned 2000 total points
ID: 37715241
While you create the child forms pass the reference of the parent form to them.
On click of the button in the main form throw an event. Now listen to these events in the child form and execute whatever you want depending on the situation.

using System;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;

namespace QuickTest {
    
    public class Class1  {
       
        public static void Main() {
            System.Console.WriteLine("Hello World!");
            Form1 f = new Form1();
            Application.Run(f);

            System.Console.ReadLine();
        }
    }
}

class Form1 : Form
{
 public delegate void ButtonClickedHandler(int i);
 public event ButtonClickedHandler ButtonClicked;
 int i=0;

 public Form1()
 {
  Button b = new Button();
  b.Click+=new EventHandler(this.Button_Clicked);
  this.Controls.Add(b);
  for(int i=0; i<3; i++)
  {
   new Form2(this).Show();
  }

}
 
 private void Button_Clicked(object o, EventArgs a )
 {
  if(ButtonClicked!=null)ButtonClicked(i++);
 }
}

class Form2 : Form
{
 RichTextBox a ;
 public Form2(Form1 f)
 {
  a = new RichTextBox();
  this.Controls.Add(a);
  f.ButtonClicked+=new Form1.ButtonClickedHandler(this.FillTextArea);
 }
 private void FillTextArea(int i)
 {
a.AppendText(""+i);
 }

}

Open in new window

0
 
LVL 3

Expert Comment

by:pradhanv
ID: 37723639
Hi pdering,
Did the posts answer your question ?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question