|
Hey I liked this control and may even use it...I made some optimizations to it and wanted to give them to you if your interested. Here is the code behind for the main control...if you want a copy of the project let me know and ill give it to you. THANK YOU this is a good idea that can be used for many different things. I tried to stick with what you already had.
=======================START CODE=================================
#Region " Types "
Private Enum eMoving
Right
Left
End Enum
Public Enum eSetType
Bounce
MoveRight
MoveLeft
End Enum
#End Region
#Region " Variables "
Private m_Col1 As Color = Color.Navy
Private m_Col2 As Color = Color.SkyBlue
Private m_Size As Integer
Private m_SpeedX As Integer = 3
Private m_MoveMe As eMoving = eMoving.Right
Private m_Type As eSetType
#End Region
#Region " Events "
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Draw(bar1, m_Col1, m_Col2)
Draw(bar2, m_Col2, m_Col1)
End Sub
Private Sub bar1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bar1.SizeChanged
Draw(bar1, m_Col1, m_Col2)
End Sub
Private Sub bar2_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bar2.SizeChanged
Draw(bar2, m_Col2, m_Col1)
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If m_Type = eSetType.Bounce Then
Dim posx As Integer = Me.bar2.Left
Dim p1L As Integer = Panel1.Left
If posx <= p1L Then : m_MoveMe = eMoving.Right
ElseIf posx >= (p1L + Panel1.Width) Then : m_MoveMe = eMoving.Left
End If
Dim theSpeed As Integer = IIf(m_MoveMe = eMoving.Left, -m_SpeedX, m_SpeedX)
bar1.Left += theSpeed
bar2.Left += theSpeed
middle.Left += theSpeed
ElseIf m_Type = eSetType.MoveRight Then
Dim p1L As Integer = Panel1.Left
Dim b2W As Integer = bar2.Width
If bar1.Left >= (p1L + Panel1.Width) Then
bar1.Left = p1L - bar1.Width - b2W
bar2.Left = p1L - b2W
middle.Left = bar2.Left - (middle.Width >> 1)
End If
bar2.Left += m_SpeedX
bar1.Left += m_SpeedX
middle.Left += m_SpeedX
ElseIf m_Type = eSetType.MoveLeft Then
Dim p1L As Integer = Panel1.Left
Dim p1W As Integer = Panel1.Width
If (bar2.Left + bar2.Width) <= p1L Then
bar1.Left = p1L + p1W
bar2.Left = p1L + p1W + bar1.Width
middle.Left = bar2.Left - (middle.Width >> 1)
End If
bar1.Left -= m_SpeedX
bar2.Left -= m_SpeedX
middle.Left -= m_SpeedX
End If
End Sub
#End Region
#Region " Subs "
Public Sub AdjustSize(ByVal size As Integer)
Dim Size5 As Integer = size * 5
bar1.Width = Size5
middle.Width = Size5
middle.Left = bar1.Left + (Size5 >> 1)
bar2.Width = Size5
bar2.Left = bar1.Left + Size5
End Sub
Public Sub Start()
If m_Type = eSetType.Bounce Then
Dim posx As Integer = bar2.Left
Dim HalfP1W As Integer = Panel1.Width >> 1
If posx <= HalfP1W - 1 Then : m_MoveMe = eMoving.Right
ElseIf posx >= HalfP1W Then : m_MoveMe = eMoving.Left
End If
ElseIf m_Type = eSetType.MoveRight Then
Dim p1L As Integer = Panel1.Left
Dim b2W As Integer = bar2.Width
If bar1.Left >= p1L + Panel1.Width Then
bar1.Left = p1L - bar1.Width - b2W
bar2.Left = p1L - b2W
middle.Left = bar2.Left - (middle.Width >> 1)
End If
ElseIf m_Type = eSetType.MoveLeft Then
Dim p1L As Integer = Panel1.Left
Dim p1W As Integer = Panel1.Width
If (bar2.Left + bar2.Width) <= p1L Then
bar1.Left = p1L + p1W
bar2.Left = p1L + p1W + bar1.Width
middle.Left = bar2.Left - (middle.Width >> 1)
End If
End If
Timer1.Interval = 5
Timer1.Start()
End Sub
Public Sub StopMoving()
Timer1.Stop()
End Sub
#Region " Private "
Private Sub Draw(ByVal bar As Panel, ByVal C1 As Color, ByVal C2 As Color)
Dim r As Rectangle = New Rectangle(0, 0, bar.Width, bar.Height)
Dim bmp As Bitmap = New Bitmap(r.Width, r.Height)
Graphics.FromImage(bmp).FillRectangle(New System.Drawing.Drawing2D.LinearGradientBrush(r, C1, C2, Drawing2D.LinearGradientMode.Horizontal), r)
If Not bar.BackgroundImage Is Nothing Then bar.BackgroundImage.Dispose()
bar.BackgroundImage = bmp
End Sub
#End Region
#End Region
#Region "Properties"
<browsable(true), category("appearance"),="" defaultvalue(gettype(color),="" "navy"),="" _
="" description("the="" first="" color="" of="" the="" control!")=""> _
Public Property Color1() As Color
Get
Return m_Col1
End Get
Set(ByVal Value As Color)
If m_Col1.Equals(Value) Then Exit Property
m_Col1 = Value
Panel1.BackColor = m_Col1
Draw(bar1, m_Col1, m_Col2)
Draw(bar2, m_Col2, m_Col1)
MyBase.Refresh()
End Set
End Property
<browsable(true), category("appearance"),="" defaultvalue(gettype(color),="" "skyblue"),="" _
="" description("the="" second="" color="" of="" the="" control!")=""> _
Public Property Color2() As Color
Get
Return m_Col2
End Get
Set(ByVal Value As Color)
If m_Col2.Equals(Value) Then Exit Property
m_Col2 = Value
middle.BackColor = m_Col2
Draw(bar1, m_Col1, m_Col2)
Draw(bar2, m_Col2, m_Col1)
MyBase.Refresh()
End Set
End Property
<browsable(true), category("behavior"),="" defaultvalue(gettype(esettype),="" "bounce"),="" _
="" description("changes="" the="" type="" of="" movement="" to="" what="" you="" want="" it="" be")=""> _
Public Shadows Property MovementType() As eSetType
Get
Return m_Type
End Get
Set(ByVal Value As eSetType)
If Value = m_Type Then Exit Property
m_Type = Value
MyBase.Refresh()
End Set
End Property
<browsable(true), category("appearance"),="" defaultvalue(gettype(integer),="" "3"),="" _
="" description("the="" speed="" at="" which="" the="" bar="" moves!")=""> _
Public Property Speed() As Integer
Get
Return m_SpeedX
End Get
Set(ByVal Value As Integer)
If m_SpeedX = Value Then Exit Property
m_SpeedX = Value
MyBase.Refresh()
End Set
End Property
<browsable(true), category("appearance"),="" defaultvalue(gettype(integer),="" "30"),="" _
="" description("the="" size="" of="" the="" scroller!")=""> _
Public Property ScrollerSize() As Integer
Get
Return m_Size
End Get
Set(ByVal Value As Integer)
If m_Size = Value Then Exit Property
m_Size = IIf((Value <= 0), 1, Value)
AdjustSize(m_Size)
MyBase.Refresh()
End Set
End Property
#Region "Hidden Properties"
<browsable(false)> Public Shadows ReadOnly Property ForeColor() As System.Drawing.Color
Get
Return Color.Transparent
End Get
End Property
<browsable(false)> Public Shadows ReadOnly Property BackColor() As System.Drawing.Color
Get
Return Color.Transparent
End Get
End Property
<browsable(false)> Public Shadows ReadOnly Property RightToLeft()
Get
Return Nothing
End Get
End Property
<browsable(false)> Public Shadows ReadOnly Property Font() As Font
Get
Return Nothing
End Get
End Property
<browsable(false)> Public Shadows ReadOnly Property BackgroundImage() As System.Drawing.Image
Get
Return Nothing
End Get
End Property
#End Region
#End Region
Pablo
|
|
|
|
|
Thanks this is nice...Small, lightweight, and it looks good. You got my 5
Pablo
|
|
|
|
|
there is another project Busybar with the same functionality
pita2000
|
|
|
|
|
I personally coded this control. There was no use of any other outside code. Plus this control was written in VB not C#.
|
|
|
|
|
Nice job i was looking for the same
|
|
|
|