Click here to Skip to main content
15,890,527 members
Home / Discussions / C#
   

C#

 
Questionis there a way?? Pin
tom_dx23-Oct-04 3:46
tom_dx23-Oct-04 3:46 
AnswerRe: is there a way?? Pin
Colin Angus Mackay23-Oct-04 4:14
Colin Angus Mackay23-Oct-04 4:14 
GeneralRe: is there a way?? Pin
tom_dx23-Oct-04 4:39
tom_dx23-Oct-04 4:39 
GeneralRe: is there a way?? Pin
Colin Angus Mackay23-Oct-04 4:41
Colin Angus Mackay23-Oct-04 4:41 
AnswerRe: is there a way?? Pin
Uwe Keim23-Oct-04 4:52
sitebuilderUwe Keim23-Oct-04 4:52 
GeneralRe: is there a way?? Pin
tom_dx23-Oct-04 14:33
tom_dx23-Oct-04 14:33 
Generalpassing a variable value to another form Pin
steve_rm22-Oct-04 20:52
steve_rm22-Oct-04 20:52 
GeneralRe: passing a variable value to another form Pin
Heath Stewart22-Oct-04 21:15
protectorHeath Stewart22-Oct-04 21:15 
As we covered in this forum many times before, it all comes down to references. In order to even set a property on the second form, your first form needs a reference to it. So, assuming the first form is the initial form (upon which, perhaps, a button click opens the second form), you need to either keep an instance of the second form or pass an instance of the first form to the second. An example of the latter follows:
class Form1 : Form
{
  Button openForm2;
  TextBox customer;
  public Form1()
  {
    openForm2 = new Button();
    Controls.Add(openForm2);
    openForm2.Click += new EventHandler(openForm2_Click);
 
    customer = new TextBox();
    Controls.Add(customer);
 
    // ...
  }
  void openForm2_Click(object sender, EventArgs e)
  {
    using (Form2 form = new Form2(this))
      form.ShowDialog(this);
  }
  // This is an example of encapsulation. Don't expose too much
  // information; only that which is required.
  public string Customer
  {
    get { return customer.Text; }
    set { customer.Text = value; }
  }
}
class Form2 : Form
{
  Form1 parent;
  public Form2(Form1 form)
  {
    parent = form;
  }
  // When you click a button or something, set parent.Customer to
  // whatever string you require.
}
This is really part of the basics of object-oriented design (OOD). You might consider picking up a book on OOD or studying many of the fine articles on this site about OOD.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralDraw Controls Pin
WDI22-Oct-04 20:32
WDI22-Oct-04 20:32 
GeneralRe: Draw Controls Pin
Heath Stewart22-Oct-04 21:21
protectorHeath Stewart22-Oct-04 21:21 
GeneralCentrally managed memory allocation/deallocation Pin
devvvy22-Oct-04 17:51
devvvy22-Oct-04 17:51 
GeneralRe: Centrally managed memory allocation/deallocation Pin
leppie22-Oct-04 20:34
leppie22-Oct-04 20:34 
GeneralRe: Centrally managed memory allocation/deallocation Pin
devvvy22-Oct-04 20:45
devvvy22-Oct-04 20:45 
GeneralRe: Centrally managed memory allocation/deallocation Pin
leppie23-Oct-04 1:45
leppie23-Oct-04 1:45 
GeneralTreeview node images Pin
sachinkalse22-Oct-04 16:26
sachinkalse22-Oct-04 16:26 
GeneralFile IO Pin
StephenMcAllister22-Oct-04 14:06
StephenMcAllister22-Oct-04 14:06 
GeneralRe: File IO Pin
Nick Parker22-Oct-04 15:37
protectorNick Parker22-Oct-04 15:37 
GeneralRe: File IO Pin
StephenMcAllister23-Oct-04 7:47
StephenMcAllister23-Oct-04 7:47 
QuestionHOW TO : BUild Dynamic Templatecolumn. Help Pin
harish h subramanian22-Oct-04 13:53
harish h subramanian22-Oct-04 13:53 
AnswerRe: HOW TO : BUild Dynamic Templatecolumn. Help Pin
Heath Stewart22-Oct-04 21:08
protectorHeath Stewart22-Oct-04 21:08 
Generalplease convert this method :) Pin
SeaMonkey00722-Oct-04 13:42
SeaMonkey00722-Oct-04 13:42 
GeneralRe: please convert this method :) Pin
Paul Lyons22-Oct-04 17:01
Paul Lyons22-Oct-04 17:01 
GeneralRe: please convert this method :) Pin
SeaMonkey00722-Oct-04 20:40
SeaMonkey00722-Oct-04 20:40 
GeneralRe: please convert this method :) Pin
Paul Lyons23-Oct-04 3:48
Paul Lyons23-Oct-04 3:48 
GeneralRe: please convert this method :) Pin
SeaMonkey00723-Oct-04 15:10
SeaMonkey00723-Oct-04 15:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.