Thread: menus interaction

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

    menus interaction

    Hi:

    I created 2 menus named: Form1, Form2 in the same solution,respectively.
    so I created a reference of Form2 and a button in Form1.
    Form2 myForm = new Form2();

    Now, the button event is myForm.Show();

    When I ran it, click the button I got Form2, so I closed the Form2, but the problem appeared if I clicked button again, it gave me such message:
    can't access a disposed object named "Form2",
    Object name:"Form2.ShowDialog"

    But if I changed to:
    myForm.ShowDialog, then no problem

    what happened??

    Thank you
    Last edited by SuperNewbie; 07-03-2002 at 04:53 AM.
    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
    My guess is that closing Form2 disposes ( destroys ) the form. So you might need to create a new Form2 every time.
    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
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187

    My guess ...

    >> so I closed the Form2

    It sounds like you closed the form manually then clicked a button that references something in that form you just closed.

    Don't close that form next time, see what happens & let us know

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Ok, things are like that:
    I click the button on Form1 to pop up Form2,
    there is a reference of Form2:
    Form myForm2 = new Form2();
    inside the button event:
    myForm2.Show();
    when I ran it:
    Form2 appeared:
    there was a close button on the Form2's right top corner, so i closed, but when I clicked that button again, then I got that kind of error, why I can't click that "X" button:

    but after I changed to myForm2.ShowDialog(). then no problem.
    Strange..
    Don't laugh at me,I am just a SuperNewbie.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    and what is the command if I control the Form2 by Form1, let's say when I click the button on Form1, then one label is created on Form2.
    I am quite newbie on C#

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 menus and resources help
    By firestorm in forum Windows Programming
    Replies: 24
    Last Post: 04-12-2005, 01:23 PM
  2. Creating pop up menus
    By Ti22 in forum C++ Programming
    Replies: 22
    Last Post: 01-18-2005, 09:27 PM
  3. Menu's
    By Benzakhar in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2004, 10:13 PM
  4. adding menus at runtime
    By bennyandthejets in forum Windows Programming
    Replies: 3
    Last Post: 11-22-2002, 05:07 AM
  5. Menus
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 04-14-2002, 04:47 PM