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

Activate and Load

Hi

just study the following code...
i have kept a command button and on its click event i have written the
following code:
(assume that there are two forms- form1 and form2 and command button is on
form1)

dim frm as new form2
frm.show
now everytime i click on this button new instance of form2 is created.

now the question is whenever i click that button i dont want to create new
instance always when its already created, i just want that form to be active
whether its hidden or active.

thanks

K
Nov 21 '05 #1
2 1373
Try:

Private m_frmForm2 As Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If m_frmForm2 Is Nothing Then ' First time
m_frmForm2 = New Form2()
m_frmForm2.Show()
ElseIf m_frmForm2.IsDisposed Then ' The form was closed
m_frmForm2 = New Form2()
m_frmForm2.Show()
Else
m_frmForm2.Activate()
End If

End Sub

--

Carlos J. Quintero (Visual Developer - .NET MVP)

The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com
"Kishan Hathiwala" <ki****@hathiwala.fateback.com> escribió en el mensaje
news:u0**************@TK2MSFTNGP11.phx.gbl...
Hi

just study the following code...
i have kept a command button and on its click event i have written the
following code:
(assume that there are two forms- form1 and form2 and command button is on
form1)

dim frm as new form2
frm.show
now everytime i click on this button new instance of form2 is created.

now the question is whenever i click that button i dont want to create new
instance always when its already created, i just want that form to be active whether its hidden or active.

thanks

K

Nov 21 '05 #2
It depneds on how you are using form2. Carolos' example will work but it puts all the emphasis on
the Calling form to monitor the restriction. A better solution is what is known as the Singleton
pattern in which you encapulation the "effect" of Carlos' code inside of Form2 itself.

It a very simple pattern to implement:

http://c2.com/cgi/wiki?SingletonPattern

hth
Richard
Nov 21 '05 #3

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

Similar topics

1
by: geotso | last post by:
Hi I'm looking for a script to activate a different stylesheet for a page, according the link a visitor clicks on. More specific, I have a page with a topic, divided into three sub-topics. I...
4
by: bughunter | last post by:
In version 7.x connect to db activate db db SQL1494W Activate database is successful, however, there is already a connection to the database. works fine - db activated. In 8.x - No!...
2
by: Randy Harris | last post by:
I'm working with Access 2K and seem to be getting some behavior that contradicts the documentation. First, the help says: "Note The Activate event doesn't occur when a form receives focus back...
10
by: zhou | last post by:
in Visual Basic ,I use Appactivate(AcadApp.caption);
5
by: Adda | last post by:
In a Parent mdi form I have a datagrid. I select a record from the grid and then invoke a childmdi form. I add the childmdi to an arraylist to keep track of it. If a user has selected multiple...
4
by: bughunter | last post by:
I'm sorry but previously command ALTER TABLE tbl ACTIVATE NOT LOGGED INITIALLY on table created without NOT LOGGED INITIALLY option was impossible. Or not? IMHO, more better give error or...
0
by: LostInMD | last post by:
Hi, I am loading word with vb2005 customized commandbars. During the load of the Word exe, the exe automatically opens a new document. I am having difficulty "activating" the open document...
3
by: pagoto123 | last post by:
i made my flash and when i loaf my site the flash have something like they are link buttons but there not . i make them do nothing on click and there is a finger when a move my mouse on the flash...
7
by: Andrus | last post by:
I have UserControls in MDI child forms containing TextBoxes and other controls. When user re-activates form, I need that Control which was last activated is activated again. Currently *first*...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
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
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...

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.