Solved

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

Posted on 2012-03-12
3
263 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
  • 2
3 Comments
 
LVL 74

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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mutually exclusive checkbox in a gridview 18 42
C# Update Status Bar.... 1 24
bulid json format 3 21
XAML: Layout 8 9
Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now