problem showing another form

This is a discussion on problem showing another form within the C# Programming forums, part of the General Programming Boards category; I have two forms in my project, and when i click a button i want it to show another form ...

  1. #1
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    problem showing another form

    I have two forms in my project, and when i click a button i want it to show another form so i put this line of code.

    Code:
    WinForm2.Show();
    It then comes up with the error message

    Code:
    An objects reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()'
    I've tried putting in System.Windows.Forms.Control.Show() with all the other declerations, but i comes up with an error. What do i need to do.
    I started out with nothing and I still have most of it left.

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    You need to create an object of the Winform2 first by doing:

    Code:
    private Winform2 foo = new Winform2();
    
    //later on in the onClickEvent of the button do 
    
    foo.Show();
    The way you are using the Show() method is as if it was in your WinForm2 class declared as a public static method.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows Form App as parent, Directx as child??
    By yetti82 in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2006, 03:04 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. New problem (tictactoe)
    By Mech0z in forum Game Programming
    Replies: 0
    Last Post: 02-03-2006, 04:19 AM
  4. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  5. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21