473,947 Members | 13,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner: How do I make form visible again?

I have a button on Form1 that hides the form and displays Form2:

Form2 myForm2 = new Form2();
myForm2.Show();
this.Hide();

After I do some work in Form2 I want to close it and redisplay Form1. I can
close the form with:
this.Close();

But how to I invoke the Show method of Form1? IOW how do I make Form1
visible again?

What I want to call while closing Form2 is "Form1.Show (); " but this throws
an object reference error.

I don't need to instantiate a new Form1. I just need to reference the one
that already exists and make it visble.

Arrrgh!!!! Can someone provide some insight?

Nov 16 '05 #1
7 8592
For this I'd setup Form2 with a constructor that takes a generic form
parameter, then in the closing event of Form2 I'd set the form that was
passed in as part of the constructor to be visible. This will allow you
to use any form as the parent of Form2 (in case it happens to be
reusable elsewhere). Hope this helps.

Have A Better One!

John M Deal, MCP
Necessity Software

Dave wrote:
I have a button on Form1 that hides the form and displays Form2:

Form2 myForm2 = new Form2();
myForm2.Show();
this.Hide();

After I do some work in Form2 I want to close it and redisplay Form1. I can
close the form with:
this.Close();

But how to I invoke the Show method of Form1? IOW how do I make Form1
visible again?

What I want to call while closing Form2 is "Form1.Show (); " but this throws
an object reference error.

I don't need to instantiate a new Form1. I just need to reference the one
that already exists and make it visble.

Arrrgh!!!! Can someone provide some insight?

Nov 16 '05 #2
Hi
There is also another way

Create our custom event in Form2 ;
Make our Form1 Subscribe for this event ; (pass the method which has the
code this.show() when subscribing )
In the closing event of Form2 call this custom Event
hope this works
regards
Ansil
Technopark Trivandrum
"Dave" wrote:
I have a button on Form1 that hides the form and displays Form2:

Form2 myForm2 = new Form2();
myForm2.Show();
this.Hide();

After I do some work in Form2 I want to close it and redisplay Form1. I can
close the form with:
this.Close();

But how to I invoke the Show method of Form1? IOW how do I make Form1
visible again?

What I want to call while closing Form2 is "Form1.Show (); " but this throws
an object reference error.

I don't need to instantiate a new Form1. I just need to reference the one
that already exists and make it visble.

Arrrgh!!!! Can someone provide some insight?

Nov 16 '05 #3
John

But then don't I have two versions of form1 in memory?

If I understand correctly, this is what I have:

On Form1:

private void button1_Click(o bject sender, System.EventArg s e)
{
Form2 myForm2 = new Form2();
myForm2.Show();
this.Hide();
}

On Form2:

private void Form2_Closing(o bject sender,
System.Componen tModel.CancelEv entArgs e)
{
Form1 myForm1 = new Form1();
myForm1.Show();
}

This displays a Form1 when Form2 closes but it is a new Form1. The original
Form1 remains hidden so now I have 2 Form1s in memory.

Is this correct?

"John M Deal" <jo******@neces sitysoftware.co m> wrote in message
news:uW******** ******@tk2msftn gp13.phx.gbl...
For this I'd setup Form2 with a constructor that takes a generic form
parameter, then in the closing event of Form2 I'd set the form that was
passed in as part of the constructor to be visible. This will allow you
to use any form as the parent of Form2 (in case it happens to be reusable
elsewhere). Hope this helps.

Have A Better One!

John M Deal, MCP
Necessity Software

Dave wrote:
I have a button on Form1 that hides the form and displays Form2:

Form2 myForm2 = new Form2();
myForm2.Show();
this.Hide();

After I do some work in Form2 I want to close it and redisplay Form1. I
can close the form with:
this.Close();

But how to I invoke the Show method of Form1? IOW how do I make Form1
visible again?

What I want to call while closing Form2 is "Form1.Show (); " but this
throws an object reference error.

I don't need to instantiate a new Form1. I just need to reference the one
that already exists and make it visble.

Arrrgh!!!! Can someone provide some insight?


Nov 16 '05 #4
Thanks Ansil

I will give this a try.

"Ansil MCAD" <An*******@disc ussions.microso ft.com> wrote in message
news:60******** *************** ***********@mic rosoft.com...
Hi
There is also another way

Create our custom event in Form2 ;
Make our Form1 Subscribe for this event ; (pass the method which has the
code this.show() when subscribing )
In the closing event of Form2 call this custom Event
hope this works
regards
Ansil
Technopark Trivandrum
"Dave" wrote:
I have a button on Form1 that hides the form and displays Form2:

Form2 myForm2 = new Form2();
myForm2.Show();
this.Hide();

After I do some work in Form2 I want to close it and redisplay Form1. I
can
close the form with:
this.Close();

But how to I invoke the Show method of Form1? IOW how do I make Form1
visible again?

What I want to call while closing Form2 is "Form1.Show (); " but this
throws
an object reference error.

I don't need to instantiate a new Form1. I just need to reference the one
that already exists and make it visble.

Arrrgh!!!! Can someone provide some insight?

Nov 16 '05 #5
Hi Dave,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to show the caller form when
Form2 is closed. If there is any misunderstandin g, please feel free to let
me know.

Here I think John means to pass the reference to the first form to Form2
when it is initialized. So we have to write another constructor for Form2.
The following is the Form2 code.

private System.Windows. Forms.Form fCaller;

public Form2(Form f)
{
this.fCaller = f;
this.Initialize Component();
}

private void Form2_Closing(o bject sender,
System.Componen tModel.CancelEv entArgs e)
{
this.fCaller.Sh ow();
}

Here is the code on Form1.

private void button1_Click(o bject sender, System.EventArg s e)
{
Form2 myForm2 = new Form2(this);
myForm2.Show();
this.Hide();
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #6
Thanks Kevin, that was a very helpful explanation.

BTW are te following 2 statements identical? They both appear to accomplish
the same thing.

this.fCaller.Sh ow();

or

this.fCaller.Vi sible=true;

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:r1******** ******@cpmsftng xa10.phx.gbl...
Hi Dave,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to show the caller form when
Form2 is closed. If there is any misunderstandin g, please feel free to let
me know.

Here I think John means to pass the reference to the first form to Form2
when it is initialized. So we have to write another constructor for Form2.
The following is the Form2 code.

private System.Windows. Forms.Form fCaller;

public Form2(Form f)
{
this.fCaller = f;
this.Initialize Component();
}

private void Form2_Closing(o bject sender,
System.Componen tModel.CancelEv entArgs e)
{
this.fCaller.Sh ow();
}

Here is the code on Form1.

private void button1_Click(o bject sender, System.EventArg s e)
{
Form2 myForm2 = new Form2(this);
myForm2.Show();
this.Hide();
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #7
Hi Dave,

Yes, they accomplish the same thing. According to MSDN document, "Showing
the control is equivalent to setting the Visible property to true. After
the Show method is called, the Visible property returns a value of true
until the Hide method is called."

You can check the following link for more information

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwind owsformscontrol classshowtopic. asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #8

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

Similar topics

13
3240
by: Martin Dennett | last post by:
Hi I'm new to this group so go easy on me! I currently use a database that has had one constant niggle for a while and I was wondering if anybody can help sort it out. From an opening screen there is an option to search for a particular record. The search criteria is entered into a text box. A form is presented over the top of the opening screen with the query results and an option is then given for another search. This results in the...
3
6836
by: Susan Bricker | last post by:
Greetings. I have three forms that are open at the same time. They are related and cascading. The first form (frmEventAdd) is the anchor. Each event can have many Trials. The second form is frmTrialInfo. Each Trial can have three Classes. The third form is frmClassInfo. These forms are used for update and adding new records. The user displays an event for update (frmEventAdd). Then clicks on a button to display the Trials for that event...
1
1117
by: suzy | last post by:
hi, if i have a web page (lets say a contact us page), where a user enters their details then clicks "send" at which point an email gets sent to the webmaster. now i have created the contact us page using the designer so the page contains plenty of text boxes etc. i want to display a simple confirmation message to the user once the user
3
1633
by: Chung Hang Shum | last post by:
I'm a beginner in ASP.Net. I'd wroten mange asp code before and now I need to transfer them from asp to asp.Net. In classical ASP you can write code like this: <% If strRequest = "ConfirmPasswd" then%> <TABLE border="0" class="ContentArea" width="100%"> <TR><TD>Change Password?</TD></TR> </TABLE> <TABLE border="0" cellPadding="2" class="ContentArea" width="100%"> <TR><TD width="27">
16
11625
by: Miguel Dias Moura | last post by:
Hello, i have 5 panels in an ASP.net / VB page. The panel 1 is visible the other 4 are NOT visible. I also have 5 images: image 1, image 2, ..., image5. When i click one of the images, image N, the panel N becomes visible and all the other invisible.
3
1519
by: nescio | last post by:
hello, i have a form with a listbox; in this listbox people can choose between 'yes' and 'no'; if the choose 'yes' i want a new text field to appear. if the choose 'no' nothing happens; but how do i do this?
8
4198
by: News Microsoft | last post by:
Hi there. I would like to know how can I test if a Form exists. This is the situation: I have a single Form in my application. My objective is, when I minimize the form, it will disapear and a TrayIcon apears in the task bar. When I click that icon, the form apears again. The problem is that when I click the icon more than once, the form apears serveral times (several instances).
1
2568
by: Robert J. Bonn | last post by:
I'm trying to set up a contact list in MS Access 97. I've looked through a reference book and the program's help screens, but the light bulb isn't quite coming on for me. If one of you could take the time to answer two very elementary questions, I'd appreciate it. Suppose the contact list consists of (for example) musicians and teachers. For every person in the list, we keep name, address, etc. For musicians, we keep track of what...
9
2398
by: Anil Gupte | last post by:
I have a MDI Parent Child set of forms FormContainer --MDIParent FormStart --MDIChild FormMain-->MDIChild FormSliceInfo-->MDIChild I use the following in the beginning of FomrContainer Public Class FormContainer Inherits System.Windows.Forms.Form
0
10164
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9983
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11168
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10693
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6117
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6332
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4947
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3543
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.