473,790 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdFind.Clic
formReplace.Sho w(
End Su

'in form
Private Sub btnCancel_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) 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 2790
try
Private Sub cmdFind_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdFind.Click
formReplace = new Form2 formReplace.Sho w()
End Sub
hope it helps

eric

"ed" <an*******@disc ussions.microso ft.com> wrote in message
news:8C******** *************** ***********@mic rosoft.com... Hi,

Here's my code:

'in form 1

WithEvents formReplace As New Form2

Private Sub cmdFind_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdFind.Click formReplace.Sho w()
End Sub

'in form2
Private Sub btnCancel_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) 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(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdFind.Click
dim formReplace as new form2
' formReplace = new Form2 formReplace.Sho w()
End Sub
I think this is better for the GC

Eric

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:OS******** ******@TK2MSFTN GP12.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.Get FolderPath(Envi ronment.Special Folder.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**********@p lanet.nl> wrote in message
news:uT******** ******@tk2msftn gp13.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
3964
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 update database or object is read-only". This is a workstation machine, not connected to any other computer, and I login to the PC using an administrator account. I already check the .MDB file is NOT read-only. But, I do not see the .LDB file....
6
14379
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 objSender,PaintEventArgs pea) { }
3
3921
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()"> <form name="Form1" method="post" action="test.aspx" id="Form1"> <script language=JavaScript> var mins, secs, timerID = null, timerRunning = false, delay = 1000; function InitializeTimer() { mins = Form1.tbMins.value; secs = Form1.tbSecs.value;...
18
28759
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, FontStyle.Bold), Brushes.Black, 0, 0) Why is this? Marc
2
4114
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 definition: Column | Type | Modifiers -------------------+------------------------+---------------------------------------------------- self | datagraph."GOLink" | not null default
0
2066
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 tried a few things that I found in postings, but I'm not getting anywhere. Please advise on what I can do. '------------------------------------------------------------ ' mcr_Export_Test '
2
4093
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 returning the error "cannot create ActiveX component" and then the program crashes. Any help is much appreciated. Thank you. Larry
5
2872
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. var oShell = new ActiveXObject("Shell32.Application");
14
3844
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, EventArgs e) { txt1 = textBox1.Text; txt2 = textBox2.Text;
5
3837
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 need help from senors please explain me about it and also indicate it in my code. Here is my code in my Class Named DBHandler!!! using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient;...
0
9512
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
10413
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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...
1
10145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
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
9021
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7530
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5422
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...
1
4094
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

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.