|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Simple VB .Net questionPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strMp3 As String strMp3 = "chop2.mp3" Me.AxWindowsMediaPlayer1.URL = strMp3 End Sub This works fine as part of a larger program and the Mp3 file plays. However, if I want to automatically push the button in the code how do I do this? I tried Button1_click () but it complains tyhat a declaration is expected? How do I do this... Also tried Button1.Enabled=True didn't work either. Also had a look here http://msdn2.microsoft.com/en-us/library/system.windows.forms.button.performclick.aspx where it says Visual Basic (Declaration) Public Sub PerformClick Visual Basic (Usage) Dim instance As Button instance.PerformClick but I find this confusing. regards Hardy
Show quote
Hide quote
"HardySpicer" <gyansor***@gmail.com> schrieb Call Sub Play whenever you want:> I have the following call from a Button1 > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Dim strMp3 As String > > strMp3 = "chop2.mp3" > > Me.AxWindowsMediaPlayer1.URL = strMp3 > End Sub > This works fine as part of a larger program and the Mp3 file plays. > > However, if I want to automatically push the button in the code how > do I do this? Public sub Play Dim strMp3 As String strMp3 = "chop2.mp3" Me.AxWindowsMediaPlayer1.URL = strMp3 End Sub Private Sub Button1_Click( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click Play End Sub Armin How about ....
Button1.PerformClick -- Show quoteHide quoteTerry "HardySpicer" wrote: > I have the following call from a Button1 > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Dim strMp3 As String > > strMp3 = "chop2.mp3" > > Me.AxWindowsMediaPlayer1.URL = strMp3 > End Sub > This works fine as part of a larger program and the Mp3 file plays. > > However, if I want to automatically push the button in the code how do > I do this? > > I tried > > Button1_click () > > but it complains tyhat a declaration is expected? How do I do this... > > Also tried > Button1.Enabled=True > > didn't work either. Also had a look here > > http://msdn2.microsoft.com/en-us/library/system.windows.forms.button.performclick.aspx > > where it says > > Visual Basic (Declaration) > > Public Sub PerformClick > > Visual Basic (Usage) > > Dim instance As Button > > instance.PerformClick > > but I find this confusing. > > regards > > Hardy > Hardy,
There are a lot of answers on your question, my favorite is Button1_Click(me,nothing) (You don't use the sender object or the eventArgs, so there is not any problem) Cor Show quoteHide quote "HardySpicer" <gyansor***@gmail.com> schreef in bericht news:0dd27053-6185-455c-88be-432d0cba9ca4@d4g2000prg.googlegroups.com... >I have the following call from a Button1 > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Dim strMp3 As String > > strMp3 = "chop2.mp3" > > Me.AxWindowsMediaPlayer1.URL = strMp3 > End Sub > This works fine as part of a larger program and the Mp3 file plays. > > However, if I want to automatically push the button in the code how do > I do this? > > I tried > > Button1_click () > > but it complains tyhat a declaration is expected? How do I do this... > > Also tried > Button1.Enabled=True > > didn't work either. Also had a look here > > http://msdn2.microsoft.com/en-us/library/system.windows.forms.button.performclick.aspx > > where it says > > Visual Basic (Declaration) > > Public Sub PerformClick > > Visual Basic (Usage) > > Dim instance As Button > > instance.PerformClick > > but I find this confusing. > > regards > > Hardy HardySpicer wrote:
Show quoteHide quote > I have the following call from a Button1 Don't.> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Dim strMp3 As String > > strMp3 = "chop2.mp3" > > Me.AxWindowsMediaPlayer1.URL = strMp3 > End Sub > This works fine as part of a larger program and the Mp3 file plays. > > However, if I want to automatically push the button in the code how do > I do this? You /could/ use ... Me.Button1_Click( Nothing, EventArgs.Empty ) .... but then you'd have to worry about null references in the click handling routine that you wouldn't do normally and, while this approach does work quite easily with, say, clicking a button, trying to invoke /other/ Control events this way - like the Mouse* ones - is horribly fiddly. You /could/ use ... Me.Button1.PerformClick() .... which simulates the user clicking the button *but* it is subject to the same limitations as the user would be; the call /only/ succeeds if the button is both Visible and Enabled, which it might not be and, if it /doesn't/ work, VB doesn't /tell/ you that it didn't work. The best solution is to extract the logic into a common routine and call it from anywhere that you need to [re-]use it. Private Sub Button1_Click( _ ByVal sender As System.Object _ , ByVal e As System.EventArgs _ ) Handles Button1.Click Me.Play( "chop2.mp3" ) End Sub Private Sub Play( ByVal sFilename as String ) Me.AxWindowsMediaPlayer1.URL = sFilename End Sub Private Sub SomeOtherRoutineThatNeedsToPlayStuff() Me.Play( "stuff.mp3" ) End Sub HTH, Phill W.
Running vb.net 2005 app under windows restricted user
sql joins in VB fast updates to textbox? Emailing a form in Visual Basic 2005 Express Need to develop an IDE add-on that would behave similar to the Find in Entire Solution colons data to datagrid Check if Mousepointer is over a region Problem Reading XML from Website AllowDrop |
|||||||||||||||||||||||