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

error: "cannot access a disposed object named 'form1'

ed
Hi,

Here's my code

'in form

WithEvents formReplace As New Form

Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Clic
formReplace.Show(
End Su

'in form
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Clic
Me.clos
End Su

What happens is on the first time that i click on the button in form 1 (cmdFind), form 2 will appear. after closing form2 and click on the button in form 1 again to show form 2, this error appears: "cannot access a disposed object named 'form1

Any ideas? thanks :
Nov 20 '05 #1
7 2771
try
Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click
formReplace = new Form2 formReplace.Show()
End Sub
hope it helps

eric

"ed" <an*******@discussions.microsoft.com> wrote in message
news:8C**********************************@microsof t.com... Hi,

Here's my code:

'in form 1

WithEvents formReplace As New Form2

Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click formReplace.Show()
End Sub

'in form2
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.close
End Sub

What happens is on the first time that i click on the button in form 1 (cmdFind), form 2 will appear. after closing form2 and click on the button
in form 1 again to show form 2, this error appears: "cannot access a
disposed object named 'form1'
Any ideas? thanks :)

Nov 20 '05 #2
Hi Ed,

As alternative from Erics solution you can use the form.showdialog

(Otherwise the user can access both in the same time, however you have
almost no control about it)

The solution is the same as Eric showed however instead of show, showdialog.

Cor
Nov 20 '05 #3
hi cor :)
as you might have noticed i'm back on winforms

but on the subject, some thoughts
a find or find an replace form shouldn't be dialog you need to be able to go
back .. also to open multiple find and replace forms.
personally i wouldn't declare form 2 like this
WithEvents formReplace As New Form2
but keep it local
Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Click
dim formReplace as new form2
' formReplace = new Form2 formReplace.Show()
End Sub
I think this is better for the GC

Eric

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OS**************@TK2MSFTNGP12.phx.gbl... Hi Ed,

As alternative from Erics solution you can use the form.showdialog

(Otherwise the user can access both in the same time, however you have
almost no control about it)

The solution is the same as Eric showed however instead of show, showdialog.
Cor

Nov 20 '05 #4
Hi EricJ,

I saw also that you have a new keyboard, with a Caps key

:-)

Somewhere is adviced for the showdialog to dispose it always however I do
not know why and therefore I set it not anymore in my samples.

I think that when you want what you say, you should not close a form however
hide it. I made a sample for that, but I think for you I can tell it as
well, the basic is that is handle the visible-change from the forms in the
main form.

Looks very nice in my opinon. And of course not one GC problem.

Cor
Nov 20 '05 #5
Hi Eric

Hi I even did not see that you did not use upercases in your text, I saw it
with Pieter and I tought, he, first I thought then he write only to Belgians
with upercases, but than I saw it was probably copied.

:-))

(I did not think about that special threathment for Belgians of course)

Cor
Nov 20 '05 #6
And I was wondering where the Caps key was coming from ;)

and if you where referring to the
Environment.GetFolderPath(Environment.SpecialFolde r.System)
that was indeed copied straight from the VS Help ;) a wonderfull place with
lots of info ;) (to bad usually a cat can't find her cittens there, you'll
know the expression)

Eric

Ps i still owe you a chinese dinner, come and get it :)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
Hi Eric

Hi I even did not see that you did not use upercases in your text, I saw it with Pieter and I tought, he, first I thought then he write only to Belgians with upercases, but than I saw it was probably copied.

:-))

(I did not think about that special threathment for Belgians of course)

Cor

Nov 20 '05 #7
ed
thanks guys :)
Nov 20 '05 #8

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

Similar topics

1
by: Fie Fie Niles | last post by:
I have IIS installed on XP Professional workstation machine. I have an ASP page that open connection to an Access database, then when trying to update the database, it gave me the error "cannot...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
3
by: Jon Natwick | last post by:
This "Countdown Timer" code works fine with Ie, but I receive an "Error: Form1 is not defined" error with Firefox 1.0.0 and 1.0.1. <body MS_POSITIONING="FlowLayout" onload="InitializeTimer()">...
18
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12,...
2
by: Florian G. Pflug | last post by:
Hi Since sometime yesterday, my postgresql (7.4.5) reports "ERROR: cannot compare arrays of different element types", when I analyze a specific table in my database. Here is the tables...
0
by: mvdkwong | last post by:
I am trying to run a macro that will export a table into a fixed length file (see below). However, when I run it, I get the following error: "Cannot update. Database or object is read-only." I've...
2
by: ironmanlarry | last post by:
Hi, I'm trying to do a mail merge from Excel to Word (programatically) and I'm having some trouble creating the Word Document Object. This line of code wordDoc = GetObject("sheet.doc") keeps...
5
by: Diego Ruiz | last post by:
Hi!! my english is not too good, but i'll try it I have a javascript code: function executeCommands(inputparms) { // Instantiate the Shell object and invoke its execute method. ...
14
by: sarabonn | last post by:
hallo Iam trying to insert a row into a access database using visual c# and iam getting an error " cannot open the action query". here is my code private void button1_Click(object sender,...
5
by: dotnetnovice | last post by:
Hi everybody actually i was trying to insert some records in to SQL server through C# Wndows Aplication and during that i face an error "Object reference not set to an instance of an object." and...
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?
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
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,...
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
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.