If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded Then
ListBox1.SelectedIndex += 1
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
AxWindowsMediaPlayer1.Ctlcontrols.play()
End If
It changes the index of the listbox, but it doesn't play the next file.
The file exist and there's no problem playing it the normal way.
Does anybody know what's wrong?
Solution is must to add timer"
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Dim item As Integer
item = ListBox1.SelectedIndex
If Form1.AxWindowsMediaPlayer1.playState = WMPPlayState.wmppsStopped Then
Me.ListBox1.SelectedIndex = item + 1
Form1.AxWindowsMediaPlayer1.URL = FileUrls(ListBox1.SelectedIndex)
Timer1.Start()
Else
Timer1.Start()
End If
end sub
also the following code work . first add timer to playlist and past following code
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Form1.AxWindowsMediaPlayer1.playState = WMPPlayState.wmppsStopped Then
If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
form1.axwindowmediaplayer1.url=listbox1.selectedindex
Else
'do nothing if no item to play
End If
End If
End Sub
Related
I want to make a program that has a counter until 5 and when reach 5 it will auto click a button and must count back from 0 - 5 again and again every time reach 5.
below is my code in timer click.
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer2.Tick
Dim ts As TimeSpan = TargetDT.Subtract(DateTime.Now)
If ts.TotalMilliseconds > 0 Then
lblTime2.Text = ts.ToString("ss")
Else
lblTime2.Text = "00"
Timer2.Stop()
btnRefresh.PerformClick()
End If
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
messagebox.show 'me dot click'
End Sub
End Class
here is my solution to my question:
when the timer tick i auto increment my label 1- 5 and when it reach 5 it will return to 0 and count again 1 - 5. and repeat. then can do something after reach 0. hope can help
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Label1.Text + 1
If Label1.Text = "5" Then
Label1.Text = 0
btnRefresh.PerformClick()
End If
End Sub
I have a list view with check box. I want to make the button visible, if item in listView is checked. If there's no checked item visible = false.
Another quick example...
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
ListView1_ItemChecked(Nothing, Nothing)
End Sub
Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles ListView1.ItemChecked
Button1.Visible = (ListView1.CheckedItems.Count > 0)
End Sub
Private Sub MOOElv_ItemChecked(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles MOOElv.ItemChecked
Dim iCount As Integer
For i = 0 To MOOElv.Items.Count - 1
If MOOElv.Items(i).Checked = True Then
iCount = 1
End If
If iCount >= 1 Then
consumebtn.Visible = True
Else
consumebtn.Visible = False
End If
Next
End Sub
Thank you i got my own solution i just put a loop inside an event handler, then first determine the amount of items and if checked the button will visible :D
How do I call this vb.net function on the button click event?
Private Sub GridView_UDGReport_DataBound1(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
For rowIndex As Integer = GridView_UDGReport.Rows.Count - 2 To 0 Step -1
Dim gviewRow As GridViewRow = GridView_UDGReport.Rows(rowIndex)
Dim gviewPreviousRow As GridViewRow = GridView_UDGReport.Rows(rowIndex + 1)
For cellCount As Integer = 0 To gviewRow.Cells.Count - 1
If gviewRow.Cells(cellCount).Text = gviewPreviousRow.Cells(cellCount).Text Then
If gviewPreviousRow.Cells(cellCount).RowSpan < 2 Then
gviewRow.Cells(cellCount).RowSpan = 2
Else
gviewRow.Cells(cellCount).RowSpan = gviewPreviousRow.Cells(cellCount).RowSpan + 1
End If
gviewPreviousRow.Cells(cellCount).Visible = False
End If
Next
Next
End Sub
Since you are not using the parameters anyways, you can simply call the method with Nothing as parameter.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GridView_UDGReport_DataBound1(Nothing, Nothing)
End Sub
Append the first line so that the sub handles more than one event, as follows:
Private Sub GridView_UDGReport_DataBound1(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound, Button1.Click
Alternatively, if you need your Click event to run some other code in addition to calling this sub, do this:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'do something
GridView_UDGReport_DataBound1(sender, e)
'do something else
End Sub
I have this code:
If RotateCount = RichTextBox1.Lines.Count Then
RotateCount = 0
End If
TextBox2.Text = RichTextBox1.Lines(RotateCount)
RotateCount += 1
The Question is... How do i get it to STOP after it reads the last line and not keep repeating?
Also, is there a way to automate it so I dont have to keep hitting the button to go to next one?
(for those who need to know this is for an automated Twitter poster for a Cryptocurrency Tipping Bot)
It wont stop because you re-assign RotateCount = 0 when RotateCount = RichTextBox1.Lines.Count it can be avoided by using
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RotateCount = RichTextBox1.Lines.Count Then
Exit Sub
End If
TextBox1.Text = RichTextBox1.Lines(RotateCount)
RotateCount += 1
End Sub
If you want to do it automatically means you need to call a time delay between read using a timer. you can achieve this by placing a timer control from the tool box and then set its interval to 5000(5sec) and enable it on button click. then the code will be
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If RotateCount = RichTextBox1.Lines.Count Then
Exit Sub
End If
TextBox1.Text = RichTextBox1.Lines(RotateCount)
RotateCount += 1
End Sub
As you see the code given below is not very useful. Is it possible to shorten the code. Mousewheel back and forward give the same result (next image). Keydown cannot be configured.
Private Sub Images_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
count += 1
If count + 1 > ImageList1.Images.Count Then
count = 0
End If
PictureBox1.Image = ImageList1.Images.Item(count)
End Sub
Private Sub Images_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel
count += 1
If count + 1 > ImageList1.Images.Count Then
count = 0
End If
PictureBox1.Image = ImageList1.Images.Item(count)
End Sub
Private Sub Images_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Down Then
count += 1
If count + 1 > ImageList1.Images.Count Then
count = 0
End If
PictureBox1.Image = ImageList1.Images.Item(count)
End If
End Sub
Here is a way to shorten this, just use function:
Private Sub Images_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = ImageList1.Images.Item(increaseCount(count))
End Sub
Private Sub Images_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel
If e.Delta > 0 Then
PictureBox1.Image = ImageList1.Images.Item(decreaseCount(count))
ElseIf e.Delta < 0 Then
PictureBox1.Image = ImageList1.Images.Item(increaseCount(count))
End If
End Sub
Private Sub Images_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Down Then
PictureBox1.Image = ImageList1.Images.Item(increaseCount(count))
End If
End Sub
Private Function increaseCount(ByRef count as integer) As Integer
count += 1
If count + 1 > ImageList1.Images.Count Then
count = 0
End If
Return count
End Sub
Private Function decreaseCount(ByRef count as integer) As Integer
count -= 1
If count - 1 > ImageList1.Images.Count OR count < 0 Then
count = 0
End If
Return count
End Sub
e.Delta is how much you scrolled, this is depending on the options in the control panel about mouse wheel scrolling. So we can't be sure what these values will be, but the good thing is that scrolling ups is always positive and scrolling down is negative.