Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi Form question 2

Status
Not open for further replies.

Terpsfan

Programmer
Dec 8, 2000
954
US
This question sounds awfully simplistic, but I have to ask. In a multi form application, I am trying to open a second form, and then close the first one. I'm able to open the second by creating a new form instance. I'm not able to close the first form. When I call this.Close it closes the entire app.

How do you close the first form?

 
This is a windows form application. Why would I be using Java Script?
 
If u use the close command i think the entire form-object shuts down. If you want to keep the object but hide the form, use Hide(). If you want to close the form u should make a new object that contains both the forms, this way you could close the first form without it making any problems for the rest of you application,
 
I used this syntax, which works. Not sure why I didn't think of this earlier. I think the problem in my earlier attempts was using the this keyword. This was referring to the 2nd form and I thought it was referring to the 1st.

Code:
frmEmployees frm = new frmEmployees();
frm.Show();
Hide();
 
Salte2 had the right concept. Remember that forms themselves are objects and need to be contained in something else.

The way the wizard starts a Windows Forms application, Form1 contains the application entry point, so if you close form1 you are closing the application. One way to handle this is to move the application entry point to a different module and open and close all froms from there. Then you don't have form1 containing the other forms.

The article here: shows this technique used for doing a splash screen and also goes more advanced by by putting the splash screen onto it's own thread.


Jeff
The future is already here - it's just not widely distributed yet...
 
Thanks Master,

That was a very informative link, which I can use for my own splash screen. I am basically creating my first C# project. I come from a Visual Basic/Access background, so I'm having to train myself how to do things in C#. I'm basically taking a 3-tier project from Visual Basic and porting it over to C#. I am learning quite a bit doing this.

 
Glad it helped. I like the architecture I got from that article. Are you converting from VB6? If so, keep in mind that VB6 and VB.NET are almost completely different animals. On the other hand, VB.NET and C# are so similar that there are online code translators. They share the same .NET object model and in their current versions, are almost the same language using two different syntaxes.

Going forward, from what I understand, MS will be diverging te features of the two, but right now you can basically use the two interchangeably.


Jeff
The future is already here - it's just not widely distributed yet...
 
I have used both VB.NET and C# for some small projects to get me acclimated. I have chosen to concentrate on C# for my training because I feel that is where Microsoft wants to really go, plus I wanted to learn a C-based language. I'm noticing a strong similarity to Java and some to C++. If I ever wanted to learn Java or C++ I would have a much easier time with it now than before.

I used the first example last night but I would like to have a timer on my splash form for about 5 seconds, then open a main menu form. Again I have done this with VB, but not sure how to incorporate this into C#. I have noticed a timer control in the toolbox and a timer_tick event handler.

Actually I have already created a data layer class to handle updating, inserting records.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top