Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open
Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private formForm2 As New Form2
+ Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then
formForm2 = New Form2
End If
formForm2.Show()
formForm2.Activate()
End Sub
End Class
This works fine except when I close Form2 and click on the command button. I
get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in
system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat 12 4188
On Tue, 26 Oct 2004 09:49:03 -0700, vvenk wrote: Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open Form2. There can only be one Form2 open at any time.
<snip>
This works fine except when I close Form2 and click on the command button. I get an exception:
When you close a form it is disposed. If you need to use the form again,
call it Hide method instead of the Close method.
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
The problem you are having is that formForm2 variable in Form1 doesn't get
set to Nothing when the Form2 closes.
You'll need to handle the close event in Form2 that needs to set this
variable to nothing.
HTH,
Regards
Simon Jefferies
mailto:simon[nospam]@cooltoolsonline.co.uk
-- remove [nospam] to email me --
"vvenk" <vv***@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com... Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1 Inherits System.Windows.Forms.Form Private formForm2 As New Form2 + Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then formForm2 = New Form2 End If formForm2.Show() formForm2.Activate() End Sub End Class
This works fine except when I close Form2 and click on the command button. I get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat
On Tue, 26 Oct 2004 09:49:03 -0700, vvenk wrote: Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open Form2. There can only be one Form2 open at any time.
<snip>
This works fine except when I close Form2 and click on the command button. I get an exception:
When you close a form it is disposed. If you need to use the form again,
call it Hide method instead of the Close method.
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
The problem you are having is that formForm2 variable in Form1 doesn't get
set to Nothing when the Form2 closes.
You'll need to handle the close event in Form2 that needs to set this
variable to nothing.
HTH,
Regards
Simon Jefferies
mailto:simon[nospam]@cooltoolsonline.co.uk
-- remove [nospam] to email me --
"vvenk" <vv***@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com... Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1 Inherits System.Windows.Forms.Form Private formForm2 As New Form2 + Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then formForm2 = New Form2 End If formForm2.Show() formForm2.Activate() End Sub End Class
This works fine except when I close Form2 and click on the command button. I get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat
set a public variable F2_Open in a module
This goes in form1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If module1.F2_Open = False Then
Dim F2 As New Form2()
F2.Show()
module1.F2_Open = True
End If
In the Closed event of the Form2 class, reset F2_Open to false. You might
also set the TopMost property of Form2 to true, so it does not appear to
vanish if the user clicks elsewhere. www.charlesfarriersoftware.com
"vvenk" wrote: Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1 Inherits System.Windows.Forms.Form Private formForm2 As New Form2 + Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then formForm2 = New Form2 End If formForm2.Show() formForm2.Activate() End Sub End Class
This works fine except when I close Form2 and click on the command button. I get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat
set a public variable F2_Open in a module
This goes in form1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If module1.F2_Open = False Then
Dim F2 As New Form2()
F2.Show()
module1.F2_Open = True
End If
In the Closed event of the Form2 class, reset F2_Open to false. You might
also set the TopMost property of Form2 to true, so it does not appear to
vanish if the user clicks elsewhere. www.charlesfarriersoftware.com
"vvenk" wrote: Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1 Inherits System.Windows.Forms.Form Private formForm2 As New Form2 + Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then formForm2 = New Form2 End If formForm2.Show() formForm2.Activate() End Sub End Class
This works fine except when I close Form2 and click on the command button. I get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat
Hi vvenk,
try the next code:
[FORM1]
Public Class Form1
Inherits System.Windows.Forms.Form
Private formForm2 As New Form2
Private Shared m_ActiveForm As Boolean
Public Shared Property ActualForm() As Boolean
Get
ActualForm = m_ActiveForm
End Get
Set(ByVal Value As Boolean)
m_ActiveForm = Value
End Set
End Property
....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not ActualForm Then
formForm2 = New Form2
End If
formForm2.Show()
formForm2.Activate()
ActualForm = True
End Sub
End Class
[FORM2]
Public Class Form2
Inherits System.Windows.Forms.Form
....
Private Sub Form2_Closed(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
Form1.ActualForm = False
End Sub
End Class
I hope that helps.
Best Regards,
Jorge Serrano Pérez
MVP VB.NET
"vvenk" wrote: Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1 Inherits System.Windows.Forms.Form Private formForm2 As New Form2 + Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then formForm2 = New Form2 End If formForm2.Show() formForm2.Activate() End Sub End Class
This works fine except when I close Form2 and click on the command button. I get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat
Hi vvenk,
try the next code:
[FORM1]
Public Class Form1
Inherits System.Windows.Forms.Form
Private formForm2 As New Form2
Private Shared m_ActiveForm As Boolean
Public Shared Property ActualForm() As Boolean
Get
ActualForm = m_ActiveForm
End Get
Set(ByVal Value As Boolean)
m_ActiveForm = Value
End Set
End Property
....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Not ActualForm Then
formForm2 = New Form2
End If
formForm2.Show()
formForm2.Activate()
ActualForm = True
End Sub
End Class
[FORM2]
Public Class Form2
Inherits System.Windows.Forms.Form
....
Private Sub Form2_Closed(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
Form1.ActualForm = False
End Sub
End Class
I hope that helps.
Best Regards,
Jorge Serrano Pérez
MVP VB.NET
"vvenk" wrote: Hello:
I have two forms, Form1 and Form2. Form1 has a command button that will open Form2. There can only be one Form2 open at any time.
Here's my code:
Public Class Form1 Inherits System.Windows.Forms.Form Private formForm2 As New Form2 + Windows Form Designer generated code "
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If formForm2 Is Nothing Then formForm2 = New Form2 End If formForm2.Show() formForm2.Activate() End Sub End Class
This works fine except when I close Form2 and click on the command button. I get an exception:
An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll
Additional information: Cannot access a disposed object named "Form2".
How do I solve this issue?
Thanks for your help.
Venkat
If formForm2 Is Nothing OrElse formForm2.IsDisposed Then
formForm2 = New Form2
End If
formForm2.Show()
formForm2.Activate()
If formForm2 Is Nothing OrElse formForm2.IsDisposed Then
formForm2 = New Form2
End If
formForm2.Show()
formForm2.Activate()
Rulin:
Of course, there is more than one way to skin the cat. But your solution is
by far the most elegant.
Thanks a lot.
"Rulin Hong" wrote: If formForm2 Is Nothing OrElse formForm2.IsDisposed Then formForm2 = New Form2 End If formForm2.Show() formForm2.Activate()
Rulin:
Of course, there is more than one way to skin the cat. But your solution is
by far the most elegant.
Thanks a lot.
"Rulin Hong" wrote: If formForm2 Is Nothing OrElse formForm2.IsDisposed Then formForm2 = New Form2 End If formForm2.Show() formForm2.Activate() This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from...
|
by: E. Robert Tisdale |
last post by:
What makes a good C/C++ programmer?
Would you be surprised if I told you that
it has almost nothing to do with your knowledge of C or C++?
There isn't much difference in productivity, for...
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode...
|
by: WindAndWaves |
last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one
of those NEVER USE.
I can understand that it may lead to confusing code, but I often use it like
this:
is this...
|
by: Keith K |
last post by:
Having developed with VB since 1992, I am now VERY
interested in C#. I've written several applications with
C# and I do enjoy the language.
What C# Needs:
There are a few things that I do...
|
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
|
by: GS |
last post by:
I got a combobox box that I load at load time. the Item and vales ended up
in reverse order of each other, what went wrong?
the database table has the following row
code value
ebay ...
|
by: tjb |
last post by:
I often see code like this:
/// <summary>
/// Removes a node.
/// </summary>
/// <param name="node">The node to remove.</param>
public void RemoveNode(Node node) {
<...>
}
|
by: Pyenos |
last post by:
import cPickle, shelve
could someone tell me what things are wrong with my code?
class progress:
PROGRESS_TABLE_ACTIONS=
DEFAULT_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=
|
by: Daniel.C |
last post by:
Hello.
I just copied this code from my book with no modification :
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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: 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,...
| |