|
-
Mar 7th, 2009, 04:57 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Form Show and Showdialog
hi im running this code to load a form and call a public method inside it:
vb Code:
[B] newForm.Show()[/B]
Call newForm.editToolStripButton_Click(sender, e)
but when i use form SHOWDIALOG method it doesnt execute
Call newForm.editToolStripButton_Click(sender, e)
-
Mar 7th, 2009, 05:08 AM
#2
Re: [2005] Form Show and Showdialog
ShowDialog is for external files, not internal forms.
-
Mar 7th, 2009, 05:31 AM
#3
Re: [2005] Form Show and Showdialog
I think you're slightly confused Hack. At least, I can't understand what you are trying to say.
jlbantang, when you call a form's ShowDialog() method, your code will not continue to execute until the form that you have shown as a dialog is closed. Here is a quick test you can use to show the concept:
Code:
Private Sub btnShowDialog_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles btnShowDialog.Click
Using frm As New newForm()
frm.ShowDialog()
MessageBox.Show("You have reached this line of code.")
End Using
End Sub
Private Sub btnShowRegular_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles btnShowRegular.Click
Using frm As New newForm()
frm.Show()
MessageBox.Show("You have reached this line of code.")
End Using
End Sub
You will notice that in the first instance, the message box only pops up when you close the newForm, whereas in the second instance, it pops up immediately.
You are having a problem because after you use the ShowDialog method, your code does not execute the
Code:
Call newForm.editToolStripButton_Click(sender, e)
until the form is closed, at which point it will fail because there is no longer a form.
-
Mar 7th, 2009, 07:13 AM
#4
Thread Starter
Fanatic Member
Re: [2005] Form Show and Showdialog
 Originally Posted by Hack
ShowDialog is for external files, not internal forms.
a bit confuse tho. I believed SHOWDIALOG is the same as showing a MODAL FORM in VB6. please correct me if im wrong.
thnx
-
Mar 7th, 2009, 07:34 AM
#5
Re: [2005] Form Show and Showdialog
Yes as Max explained, ShowDialog will block the calling thread until the form shown by the ShowDialog call is closed.
I should also point out that it is considered bad practise to call eventhandlers directly, you should avoid that.
-
Mar 7th, 2009, 09:06 AM
#6
Re: [2005] Form Show and Showdialog
Code that will be called from multiple locations should be wrapped in its own method.
-
Mar 7th, 2009, 01:59 PM
#7
Thread Starter
Fanatic Member
Re: [2005] Form Show and Showdialog
thnx. so i wrapped the codes in its own method and still nothing seems to work. what would you suggest experts?
-
Mar 7th, 2009, 02:12 PM
#8
Re: [2005] Form Show and Showdialog
what does not seem to work and how are you trying to do it?
-
Mar 7th, 2009, 02:14 PM
#9
Frenzied Member
Re: [2005] Form Show and Showdialog
Well things are wrong with calling into a sub that listens to a UI elements events. You are simulating that the relevant object sent the message. Objects are supposed to tell the outside world that something happened to the object, not the outside world telling the rest of the program that an object raised an event when it didn't. You can do it, but your screwing with the way OOP was meant to operate.
What to do?
Just make another sub that contains the code you want to execute and call it instead.
-
Mar 7th, 2009, 02:26 PM
#10
Re: [2005] Form Show and Showdialog
you don't need to call the form's
vb Code:
editToolStripButton_Click(sender, e) sub
. if you do than you need to provide the event args for the click and that is what i don't see you doing. Instead call the button's performClick method.
vb Code:
newForm.Show()
newForm.editToolStripButton.PerformClick()
-
Mar 7th, 2009, 02:36 PM
#11
Frenzied Member
Re: [2005] Form Show and Showdialog
Even then the code is a little screwball because you are using the sub both to catch events from within an object, and for external use.
That sort of muddies the water of the purpose of event handlers.
And before you say it...
Remember "Goto"
-
Mar 8th, 2009, 01:43 AM
#12
Thread Starter
Fanatic Member
Re: [2005] Form Show and Showdialog
i supposed to used SHOWDIALOG but since the required step wont allow me to perform a method local to the external form i will use SHOW method instead and that fix all issues.
tnx.
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
|