473,405 Members | 2,176 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,405 software developers and data experts.

Coping with more than one form - i'm new to this stuff

Hi guys,

This is probably a really simple silly question, but I can't seem to
find a way round it.

I want to display a separate form when I click on a link label on my
main form. I've managed that, but it displays a second form when you
click again because the click event is creating a new instance of the
form each time. How do I go about creating one instance of the form
and displaying it with the click event? This needs to work again
after the form has been closed. The GC seems to dispose of the form
after you close it so calling show() again is obviously a bad idea.
Is there a way of using the visible property when you click on X to
hide the form rather than disposing of it or are there better
ways...I expect there are...please enlighten me. I feel stupid! :(

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 21 '05 #1
3 1094
What you need is a global variable that holds the reference the form. When
the user clicks the button check to see if the variable is nothing/null and
if so then create an instance of the form and show it.

If the variable is not nothing then just show the form. You are most likely
seeing a Dispose since the variable holding the form instance goes out of
scope.

Lloyd Sheen

"mark_t1980" <ma********@hotmail-dot-com.no-spam.invalid> wrote in message
news:40**********@127.0.0.1...
Hi guys,

This is probably a really simple silly question, but I can't seem to
find a way round it.

I want to display a separate form when I click on a link label on my
main form. I've managed that, but it displays a second form when you
click again because the click event is creating a new instance of the
form each time. How do I go about creating one instance of the form
and displaying it with the click event? This needs to work again
after the form has been closed. The GC seems to dispose of the form
after you close it so calling show() again is obviously a bad idea.
Is there a way of using the visible property when you click on X to
hide the form rather than disposing of it or are there better
ways...I expect there are...please enlighten me. I feel stupid! :(

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Jul 21 '05 #2
Hi!

Thanks for the advice. I had tried this, but somehow checking for the
null reference doesn't work. The code I have is as follows:

private AutoPlate.frmPrdDatEnt fPrdDatEnt; //My global variable decl.

this.fPrdDatEnt = new frmPrdDatEnt(); //Assign variable ref. to form
inst.
//Click event code is then...
private void lnkProdDatEnt_LinkClicked(object sender,
System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
if (fPrdDatEnt == null)
{
InitialiseScreen();
fPrdDatEnt.Show();
}
else
fPrdDatEnt.Show();
}

The InitialiseScreen() function just has one line in it which is:
frmPrdDatEnt fPrdDatEnt = new frmPrdDatEnt();
//to create a new instance of the form after it has been closed.
Unfortunately, the form is opening once, but then once closed upon
trying to open it again, it crashes with a 'Cannot access a disposed
object named "frmPrdDatEnt"' exception. It would seem it's still
going through the else of the if statement...any ideas why?

Thanks guys...

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 21 '05 #3
OK...I realised the separate function to create a new instance was
silly cos that just goes out of scope. It does seem though, that when
the GC disposes of the form it doesn't set the reference variable to
null. Is there anything else I can do to test for if the form has
been disposed of?

Thanks...

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 21 '05 #4

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
3
by: sasha_lui | last post by:
Hi al, What should i do so people cant copy or save my homepage. Regards Sasha
116
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data...
5
by: Fresh Air Rider | last post by:
Hello Could anyone please explain how I can pass more than one arguement/parameter value to a function using <asp:linkbutton> or is this a major shortfall of the language ? Consider the...
3
by: mark_t1980 | last post by:
Hi guys, This is probably a really simple silly question, but I can't seem to find a way round it. I want to display a separate form when I click on a link label on my main form. I've managed...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
1
by: =?Utf-8?B?R2VuY3k=?= | last post by:
Hi, I'm having a problem the coping cd's etc option is missing in Media Center. It used to be available but it has just disappeared! Can anyone help. Thanks
1
oll3i
by: oll3i | last post by:
what are coping constructors and reflexion for ? thank YOU
5
by: Dmitriy Lapko | last post by:
Hallo all Is it possible to change schema of table in DB2 v.8.2 without recreating and coping a table into a new schema? I need it for several purposes, one of them - refactoring of existing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.