473,397 Members | 1,949 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,397 software developers and data experts.

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 8547
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(object sender, System.EventArgs e)
{
Form2 myForm2 = new Form2();
myForm2.Show();
this.Hide();
}

On Form2:

private void Form2_Closing(object sender,
System.ComponentModel.CancelEventArgs 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******@necessitysoftware.com> wrote in message
news:uW**************@tk2msftngp13.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*******@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.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 misunderstanding, 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.InitializeComponent();
}

private void Form2_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
this.fCaller.Show();
}

Here is the code on Form1.

private void button1_Click(object sender, System.EventArgs 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.Show();

or

this.fCaller.Visible=true;

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:r1**************@cpmsftngxa10.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 misunderstanding, 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.InitializeComponent();
}

private void Form2_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
this.fCaller.Show();
}

Here is the code on Form1.

private void button1_Click(object sender, System.EventArgs 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/
frlrfsystemwindowsformscontrolclassshowtopic.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
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...
3
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...
1
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...
3
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"...
16
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,...
3
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; ...
8
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...
1
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...
9
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 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.