Click to See Complete Forum and Search --> : How can I go from one form to another


Suzi167
March 15th, 2006, 09:46 AM
I have a multiple forms application and on form # 1 there is an OK button.
I want to click on it and go to Form # 2
In VB all yuo need to do is Form2.show
How is it done in C#???

Thanks very much in advance for any suggestions.

Susan

Athley
March 15th, 2006, 09:54 AM
Do you find the answer in This (http://www.codeguru.com/forum/showthread.php?t=379700) thread?

/Leyan

Suzi167
March 15th, 2006, 10:01 AM
Seems as it will stir me in the right direction.

Thanks very much.

Suzi167
March 15th, 2006, 10:20 AM
hello Athley,

The code belo wis very good.
I just have one confusion.
I am trying to migrate from a VB mind set to C# mindset so please don't mind me if the questions I am asking are silly.

When I create a new form ( Form2 for example) the environment automatically creates some code (see below)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Configuration_Software
{
public partial class frmSelect_Action : Form
{

// here I can put the functions which apply to the variaety of members
//on the form

}

The first question I have is:

1) However from what I've seen so far it seems like this is a wrong way to
approach application writing becasue it is not very object oriented.
So Do you think I should NOT use the code generated by the
environment and make my own?

And the second question I have is this:

2) Right now I have Form#1 come up automatically when I try to run the
application. If I implement a main in which I call all the onjects then how
can I set mu application to go to MAIN() first a nd not to Form!.


Athley, thank you vey much..really.

Athley
March 15th, 2006, 11:00 AM
1) What the designer does for you is to create code for you that is inherited from the Form object that is inherited from Control... bla, bla.... wich is OOP in itself. So if you feel that what the Form object gives you is exaclty what you want and you just want to add a few Methods and so on, I would just be pleased with what it does for me. That is my opinion, and I know that some people will disagree.... my most important motto is: "Do not invent the wheel again". :)

But then again if you have alot of things that you want to change about the Form object, of course, create your own, that way you could reuse your own Form object later with ease.

2) You set that in the project properties. Project/Configuration_Software Properties/Application/Starup object in the menu.

/Leyan

Suzi167
March 15th, 2006, 01:29 PM
Thanks.

OK so I get it - the form1 that I create for example is my main class and then I dynamically have to create forms that will be of type Form1...but

Let's say I create form1 with two buttons OK a nd Cancel
and then in main I write:

Form1 FirstFOrm = new Form1();

That will create an instance of my Form1 class.

But then how can I access the event which happens when you click the OK button on Form1 which I created.
Going from OOP rules when I click FirstForm. I should get all the members of the Form1 class and cmdOK is one of them. But I don't ..... so I am a bit confused.... How in code can I ..." do something when the OK button is clicked"
, in other words how can I access the events for cmdOK through FistForm????

Thanks :)

Suzi167
March 15th, 2006, 01:32 PM
OK I ound out how.... :) - I need to declare the member to be public and then it shows. : )