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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding and reshowing Custom Dialogs

Status
Not open for further replies.

NichP

Technical User
Sep 6, 2007
2
US
I am new to VB programming and need some help with hiding and showing custom dialog boxes. I have designed a dialog box which when opened uses the "shown" event to preload values into comboboxes and solicites user input. The basic code is below. When the dialog is closed, I want to be able to reopen it without changing the users data or reloading the comboboxes

The first time through it works fine. The next time through I cannot get the dialog to show without redefining the instance. The code below appears as though it should work but it will not display the dialog.

Any help would be greatly appreciated.

Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

Try
Primary.Show()
Catch ex As NullReferenceException
dim Primary as New ResinClass
Primary.ShowDialog()
Finally
If Primary.DialogResult = Windows.Forms.DialogResult.OK Then
Primary.Hide()
Else
Primary.Dispose()
End If
End Try

End Sub

 
You need to store the data you need somewhere (in your main form) and give yourself a way to pass it in when you create a reference to Primary. Remember that when you Dispose(), everything you had in Primary is gone (for all intents and purposes). So your question really becomes 'how can I pass data between two forms'

Knowing the new question, this FAQ's will probably help you faq796-5773

Hope it helps,

Alex

[small]----signature below----[/small]
With all due respect, Don Bot, I don't think we should rely on an accident happening. Let's kill him ourselves.

Ignorance of certain subjects is a great part of wisdom
 
Alex;

Thank you for the link. I will check it out.

When the user responds with the "OK" in the dialog the form should be hidden. It should only be disposed when the something other than "OK" is responded.

I tried an experiment hiding and showing a dialaog within the same subroutine and it worked fine. I have also tried placing the dim statment at the top of the class and using a set statement in the subroutine.




 
the:

Dim Primary As New Form

needs to be global

then in ur code do:

Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

Try
Primary.Show()
Catch ex As NullReferenceException
Primary = New ResinClass
Primary.ShowDialog()
Finally
If Primary.DialogResult = Windows.Forms.DialogResult.OK Then
Primary.Hide()
Else
Primary.Dispose()
End If
End Try

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top