I tried to make a medaiplayer with custom controls and the customcontrols is made with drawing.
Looking like this:
it works to change the value without any error...but the time/duration of the song doesn´t change at all :S
My Code:
Code:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices
Public Class Form1
Dim WithEvents myslidercontrol As New MySlider
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myslidercontrol.PositionPos = 0
myslidercontrol.Location = New Point(10, 10)
myslidercontrol.Size = New Size(200, 100)
Me.Controls.Add(myslidercontrol)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'load song
End Sub
Private Sub PositionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles myslidercontrol.PosChanged
Try
If (AxWindowsMediaPlayer1.currentMedia.duration <> 0) Then
Dim NewPerc As Double = Convert.ToDouble(myslidercontrol.Size.Width) / 100
Dim DurationVar As Integer = Convert.ToInt32(AxWindowsMediaPlayer1.currentMedia.duration * 1000) ' milliseconds
Dim NewPos As Integer = (DurationVar * NewPerc) / 1000
AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = NewPos
Else
myslidercontrol.pos = 0
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub DurationTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DurationTimer.Tick
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPlaying Then
Dim CurPos As Integer = Convert.ToInt32(AxWindowsMediaPlayer1.Ctlcontrols.currentPosition * 1000)
Dim DurationVar As Integer = Convert.ToInt32(AxWindowsMediaPlayer1.currentMedia.duration * 1000)
If DurationVar > 0 Then
myslidercontrol.pos = Convert.ToInt32((CurPos * 100) / DurationVar)
End If
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
DurationTimer.Enabled = False
myslidercontrol.pos = 0
End If
Else
End If
End Sub
End Class
Public Class MySlider
Inherits UserControl
Public pos As Integer 'Position of the slidepoint
Public MouseInUse As Boolean
Public Event PosChanged(ByVal sender As Object, ByVal e As EventArgs)
''''from here, nearly all i just took from that project
Public Property PositionPos()
Get
Return pos
End Get
Set(ByVal Value)
If (pos > -1) And (pos < 11) Then
pos = Value
Else
Throw New ArgumentOutOfRangeException(PositionPos, "Must be between 0 to 10")
End If
End Set
End Property
Protected Overrides Sub onpaint(ByVal e As PaintEventArgs)
Dim xsize As Integer = Me.Size.Width
Dim ysize As Integer = Me.Size.Height
Dim TheDot As Graphics = Me.CreateGraphics
TheDot.SmoothingMode = SmoothingMode.AntiAlias
TheDot.PixelOffsetMode = PixelOffsetMode.None
TheDo*****mpositingQuality = CompositingQuality.HighQuality
e.Graphics.DrawLine(Pens.Black, (xsize \ 10) - xsize \ 10, 15, xsize - xsize \ 10, 15) 'centerline
TheDot.FillEllipse(Brushes.Black, (xsize \ 10) * pos - 4, 11, 8, 8) 'Dot at pos
End Sub
Private Sub MouseDownHandler(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
Dim oldpos As Integer = pos
MouseInUse = True
Me.Cursor = Cursors.Hand
pos = Convert.ToInt32((e.X / Me.Size.Width) * 10)
Me.Invalidate()
If pos <> oldpos Then RaiseEvent PosChanged(sender, New EventArgs)
End Sub
Private Sub MouseUpHandler(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
MouseInUse = False
Me.Cursor = Cursors.Default
End Sub
Private Sub MouseMoveHandler(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
If MouseInUse Then
Dim oldpos As Integer = pos
pos = Convert.ToInt32((e.X / MyBase.Size.Width) * 10)
MyBase.Invalidate()
If pos <> oldpos Then RaiseEvent PosChanged(sender, New EventArgs)
End If
End Sub
' to here but i have made som major changes ^^
End Class
Someparts did i take from another project i found at the internet some while ago. For the Scrollbar value and pos
I got 1 more quesion i have one/two line that i dont understand its marked below
Code:
'at the top:
Public Event PosChanged(ByVal sender As Object, ByVal e As EventArgs)
'in action xD
If pos <> oldpos Then RaiseEvent PosChanged(sender, New EventArgs)
Someone skilled at VB plz help me