473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How close/open forms in Windows app?

I know how to close and open a form...

Well.. but can you tell me how can I do this.....

Example...

There are 2 forms...named formA and formB and each of them have their own
button named btnA and btnB

The application starts with formA

can you show me the code that... when I click on btnA in formA, It will
CLOSE formA and open formB...

Then when I click btnB from formB, it will close formB and open back formA

How can I do this? I don't want their visible set to .false

I want them really close and use no resources from my computer.. How?

Thanks for your help....
Oct 8 '06 #1
3 10640
In btnA's click event:

FormB b = new FormB();
b.Show();
this.Close();

Similarly in btnB's click event:

FormA a = new FormaA();
a.Show();
this.Close();

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:ef**************@TK2MSFTNGP04.phx.gbl...
I know how to close and open a form...

Well.. but can you tell me how can I do this.....

Example...

There are 2 forms...named formA and formB and each of them have their own
button named btnA and btnB

The application starts with formA

can you show me the code that... when I click on btnA in formA, It will
CLOSE formA and open formB...

Then when I click btnB from formB, it will close formB and open back formA

How can I do this? I don't want their visible set to .false

I want them really close and use no resources from my computer.. How?

Thanks for your help....
Oct 8 '06 #2
"Ronald S. Cook" <rc***@westinis.comwrote in message
news:ef**************@TK2MSFTNGP04.phx.gbl...
There are 2 forms...named formA and formB and each of them have their own
button named btnA and btnB

The application starts with formA

can you show me the code that... when I click on btnA in formA, It will
CLOSE formA and open formB...

Then when I click btnB from formB, it will close formB and open back formA
There may be other ways, but the most straightforward way I know of is to
use the Application.Run() overload that has no parameters, and then show
each form explicitly. You'll have to edit the Program class's Main() method
to do this, opening the form first desired ("formA" in your example)...each
button will close its owning form and show the other one.

You'll also have to add something to explicitly exit the
application...probably handle that in the close event of each form, in which
the Application.Exit() or Application.ExitThread() method is called unless
the form was explicitly closed by the button that opens the other form.

Here is some sample code (minus all the default stuff...hopefully it's
reasonably clear where you would have to add this):

In the Program.Main() method (replaces the default statement,
"Application.Run(new Form1())"):

(new Form1()).Show();
Application.Run();
In each of the forms you want, something like this (in addition to
everything else...and of course, the two new methods need to be hooked up in
the designer to the correct events):

public partial class Form1 : Form
{
private bool _fExitAppOnClose = true;

private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();

_fExitAppOnClose = false;
form2.Show();
Close();
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (_fExitAppOnClose)
{
Application.Exit();
}
}
}


Oct 8 '06 #3
Ronald,

Have a look at the

Environment.Close(0); // the 0 means normal exit

Cor

"Ronald S. Cook" <rc***@westinis.comschreef in bericht
news:ef**************@TK2MSFTNGP04.phx.gbl...
>I know how to close and open a form...

Well.. but can you tell me how can I do this.....

Example...

There are 2 forms...named formA and formB and each of them have their own
button named btnA and btnB

The application starts with formA

can you show me the code that... when I click on btnA in formA, It will
CLOSE formA and open formB...

Then when I click btnB from formB, it will close formB and open back formA

How can I do this? I don't want their visible set to .false

I want them really close and use no resources from my computer.. How?

Thanks for your help....

Oct 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jrefactors | last post by:
>From the main page, there are lots of links to open new window. i.e. <a href="#" onClick="window.open('child1.html')">Open Child Window</a> If I close the main page, I want to close all child...
0
by: markusp1982 | last post by:
Hello NG, I want to close open files which are locked by other users. I like to update an file. I dont want to delete the share file/folder. In the Computer Mangagement you can remove(cut) all...
2
by: Paul Steele | last post by:
Is there any way to check for open Explorer windows and if any are found, tell Windows Explorer to close them. I don't want a brute force method of killing Explorer and letting it restart. I'd...
3
by: Isabel | last post by:
How can you close all child browser windows that where open by a parent browser window? I have links on a parent (main) page that opens the child page as a separate browser. However, I need to be...
1
by: Bryan | last post by:
What are some of the methods you guys have used to update data in forms that has been changed by another open form? For example I might open an form to edit an employee, and when I close it I...
3
by: rdemyan via AccessMonster.com | last post by:
I need help with code to close two forms at the same time, FormA and FormB. I need code that can be used from either form and needs to work with both a 'Close' button on each form as well as if the...
6
by: Ryan | last post by:
My application has a main form from which the user can use the Menu to open other forms. Each form opens in a separate window while the main form remains open all the time. Is their any code I...
4
by: robert.waters | last post by:
Hello, I have a main form that is maximized when my application loads; this main form contains links to all other forms. I've had to specify the Popup property of these other forms, so that...
4
by: nottarealaddress | last post by:
I'm trying to get my feet wet in VB2005 (our new standard at work after officially stopping new development in VB6 about a month ago). I'm working with a simple sql 2005 table of 50 entries, one...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.