Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello .

 

I have used this line of code to open a new form :

 

Dim frmdataform3 As New DataForm3()

frmdataform3.Show()

 

This works fine but i find if user re-clicks on the button another copy of the form opens , it allows several copies of the same form to be open ...

 

How can i get it so that only 1 copy is to be open at any one time ?

 

sort of like :

 

if form open = true then dont open

 

:)

 

Thanks for help

 

Regards

Carl

  • Administrators
Posted

in the DataForm3 you could add some thing like


Private Shared _IsOpen As Boolean

Public Shared ReadOnly Property ISOpen() As Boolean
	Get
		Return _IsOpen
	End Get
End Property

 

in the form load event add

_IsOpen = True

 

and

in the form closed event add

_IsOpen = false

 

in the code that creates the form you can now use code similar to

if DataForm3.Isopen = false then
'donothing
else
'create form here
end if

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

U sure that work, PlausiblyDamp ? :confused:

I dont think it work becurse he declarar the form in the function, and it will be declarar again as a new then he call the function again.

  • *Experts*
Posted

Declare your form as new on the top of your class, then from where ever you are calling just call it as

FormName.Show()

It will keep calling the same instance.

Posted

Why don't you keep your own boolean flag to indicate, whether form3 is already open or not ?

 

Or search for "Singleton" in this forum. The singletin design patter makes sure that a class is only instantiated once.

.nerd

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...