|
-
Jul 19th, 2004, 08:04 AM
#1
Thread Starter
New Member
Using ShowDialog
I'm having problems using dialog windows in my program. Specifically when I call a
window using the ShowDialog in an SDI environment.
I have a main form that calls a dialog:
VB Code:
dim frm as new frmMaps
frm.ShowDialog
in frmMaps I have 2 buttons that call another dialog (Add/Edit)
VB Code:
dim frm as new frmEditMap
frm.ShowDialog
Problem arrises when I click close on the frmEditMap:
VB Code:
Me.DialogResult = DialogResult.Cancel
Me.Close
However, for some reason this also closes the parent, frmMaps.
Essentially my goal is to have only once instance of frmMaps.
Cheers,
Tom
-
Jul 19th, 2004, 09:16 AM
#2
PowerPoster
How did you create the instance of the Main Form?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 09:33 AM
#3
Thread Starter
New Member
dim f as new frmMain
Application.Run(f)
-
Jul 19th, 2004, 09:57 AM
#4
PowerPoster
Hi,
Sorry I misread your original post.
You have used the variable "Frm" to hold the instance of frmMaps AND then replaced it with frmEditMap. Change the instance name of one of them to frm1.
If in run mode you move the form which is "on top" i.e. the instance of frmEditMap, you will find that the instance of frmMaps has already been closed.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 10:05 AM
#5
Thread Starter
New Member
Those variables are declared within each function, I didn't think they were shared out of scope.
Cheers,
-
Jul 19th, 2004, 10:07 AM
#6
PowerPoster
Originally posted by BlackThunder
Those variables are declared within each function, I didn't think they were shared out of scope.
Cheers,
The effect is the same, once they go out of scope they are destroyed.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 19th, 2004, 10:18 AM
#7
Hyperactive Member
If I well understand (always I have to premit this consideration )the button you use to instance your child form has property DialogResult not set to 'None'. So when the child form close and code in parent's button click procedure can come to its end it close itself, too. I say this assuming your parent form is modally showed, too. If not forgive all!
Live long and prosper (Mr. Spock)
-
Jul 19th, 2004, 10:45 AM
#8
Thread Starter
New Member
It would seem that settings
Me.DialogResult = DialogResult.None
at the end of the button code works, what an odd implementation tho.
-
Jul 19th, 2004, 11:00 AM
#9
Hyperactive Member
Uhmmm, obviously it's possible there is another reason, but what I'm trying to check is if the property of button in your Parent form is set to dialogresult=none. You can check it at design mode. I'm not sure to have understood where the code 'Me.DialogResult = DialogResult.None' is placed, but you need only to test the button's property from property window and you can have a confirm or not. If the parent's button has property setted to something different then 'None' it will close your parent Form at the end of its routine....only if your parent is modal, obviously. If not.....sorry!
Live long and prosper (Mr. Spock)
-
Jul 19th, 2004, 11:06 AM
#10
Thread Starter
New Member
here's the breakdown of the code
in frmMain
VB Code:
Private Sub mnuFavorite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFavorite.Click
Dim fmaps As New frmMaps
fmaps.ShowDialog()
End Sub
in frmMaps
VB Code:
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
Dim fe As New frmEditMap
Dim map As clsMap
fe.Init()
If fe.ShowDialog = DialogResult.OK Then
map = New clsMap
map.Map = fe.txtMap.Text
map.Game = fe.cmbGames.Text
map.CaseSensitive = fe.chkCase.Checked
map.PartialMatch = fe.chkPartial.Checked
map.ID = maps.Count
maps.Add(map)
End If
fe.Dispose()
fe = Nothing
Renumber()
Populate()
Me.DialogResult = DialogResult.None
End Sub
in frmEditMap
VB Code:
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub
-
Jul 19th, 2004, 12:29 PM
#11
Hyperactive Member
I've tried some simulations, but your code seems correct. The only thing remains to check is if your FrmMaps is hidden by a procedure. To Hide a Modal Form cause it return also with dialogresult = none. If not, I hope a more experienced friend will help you! Good luck and good job!
Live long and prosper (Mr. Spock)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|