Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toolstrip in template - be sure form closed before opening again

Status
Not open for further replies.

surfside1

Programmer
Feb 12, 2006
209
US
I have a toolstrip in a template. The various buttons link to the other forms in the application that have inherited the toolstrip. My problem is that when the buttons link to other forms using the ShowDialog() and they have been opened previously, I get the error that I'm attempting to open a form that is already open. What code do I use to make sure the form is closed before it attempts to open it again. I thought the .Visible = False was what I should set, before the ShowDialog(), but no.

What approach should I use, how do you close a form when it links to another form. There's no need to have more than one form open at a time. I'm certain this is elementary. Thank you.
 
just because a form.visible = false, doesnt mean the form is "closed"

if you are explicitly opening a form you can do something like:

if myForm.Open then
myForm.Close
end if

myForm.Open()
'or
myForm.ShowDialog()


if you are having a problem where you already have a dialog open, but it is not the one that you are attempting to open, then you will have to go back and do some cleanup on your .visible = false and change it to .close().

-The answer to your problem may not be the answer to your question.
 
Quick question, what is the difference in Open and ShowDialog?
 
I believe showDialog is a modal window, which doesn't allow you to switch to a different window, until the current one is closed.

-The answer to your problem may not be the answer to your question.
 
Ok I'm new to VB so this is the first I have seen the ShowDialog. I am using ShowDialog and it does open a new window. That is why I was asking about the closing the form before attempting to open it again? Oh well, thanks for your help on the syntax and I'll give it a try. Thank you!
 
I'm having some problems and I'll look at it in the am.
Thanks for your help!
 
I'm coding the following below. But I'm getting the error that "Open is not a member of Auctions_Listings.frmAuctionListings. And in fact it does not give me an option to select "Open" after I type the "." (period). What am I missing?

Private Sub toolstripAuctionListings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolstripAuctionListings.Click
If My.Forms.frmAuctionListings.Open() Then
My.Forms.frmAuctionListings.Close()
End If
My.Forms.frmAuctionListings.ShowDialog()
End Sub
Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top