Thread: forms!!!???

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    forms!!!???

    Hello:
    If there is one form1 with menu items and one textbox on it, textbox is public type,I click the menu item,
    another form2 with a button pops up, and how could I point the textbox on form1,

    because if I create such
    form1 myform1 = new form1();
    form1.textbox.Text = "test";
    on form2 button events
    it didn't work, because this myform1 is another memory copy of form1, so, what should I then?

    Thank you!!
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Your form2 needs a variable of type form1 that has to be set to myform1 before shosing form2. Then you can do whatever you want on form1.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Thanks, but can you write a simple code to illustrate this, I got a little bit confused
    Don't laugh at me,I am just a SuperNewbie.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    and somehow, each form is a independ class, so I can't define such global form instance that can be used in both forms
    Don't laugh at me,I am just a SuperNewbie.

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    I'm a bit too lazy to type code today...


    In your form2 class, make a public variable of type form1 and call it parent.

    If your form1 class, after creating the variable of type form2, set it's parent to this. Then in form2 you can access the form1 variable through the variable parent.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    ok, so in form1:
    i did like this:
    Form2 form2 = new Form2();
    form2.Parent = this;
    then
    form2.Show();

    in form2;
    public Form1 form1;
    form1 = Parent; // but i get errors


    by the way, is this working for MDI things?

    thanx!
    Don't laugh at me,I am just a SuperNewbie.

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    This is not what I said. If you want the above solution look again at what I wrote and follow it step by step.

    However, Forms obviously already have a Parent property, you just need to use it. In your form2, you can access form1 by calling
    ((Form1)Parent).WhateverYouWantOfForm1.

    Example:

    In form2:

    ((Form1)Parent).Title = "Changing fom1's title";
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Good introduction to Windows Forms?
    By jcafaro10 in forum C# Programming
    Replies: 1
    Last Post: 05-19-2009, 06:11 PM
  2. Replies: 2
    Last Post: 04-02-2009, 04:40 AM
  3. Closing all forms from a derived form
    By Pete_O in forum C# Programming
    Replies: 1
    Last Post: 09-01-2007, 01:09 PM
  4. C# Game using Forms
    By ejohns85 in forum C# Programming
    Replies: 1
    Last Post: 12-16-2006, 05:35 PM
  5. Which one :MFC, Win32, Windows Forms (.Net)?
    By Robert_Sitter in forum Windows Programming
    Replies: 6
    Last Post: 11-17-2005, 06:15 AM