I like this control of yours very much. May I use your code in a school project I'm working on at the moment? I will, of course, credit you for the code, as well as citing this site as the location I got it from. Please note that I may need to make some minor changes and tweaks to make it blend in with the rest of my project, however the implementation and effect of the control will stay unchanged.
Please rate helpful ppl's posts. It's the best 'thank you' you can give
I'd like to report an issue with the control: when the scrolling direction is set to Left, the text "jumps" into view all at once instead of scrolling in. Could you please have a look?
Please rate helpful ppl's posts. It's the best 'thank you' you can give
I fixed the issue. Have a look at the original OnPaint:
Code:
Private Overloads Sub OnPaint(ByVal sender As Object, _
ByVal e As PaintEventArgs)
Dim str As String = m_MarqueeText
Dim g As Graphics = e.Graphics
Dim szf As SizeF
g.SmoothingMode = SmoothingMode.HighQuality
szf = g.MeasureString(m_MarqueeText, Me.Font)
If m_LeftToRight = Direction.Right Then
If startPosition > Me.Width Then
startPosition = -szf.Width
Else
startPosition += 1
End If
ElseIf m_LeftToRight = Direction.Left Then
If startPosition < -szf.Width Then
startPosition = szf.Width 'Because of this line, the text will start a width of the text to the right instead of from the right edge of the control
Else
startPosition -= 1
End If
End If
g.DrawString(m_MarqueeText, Me.Font, New SolidBrush(Me.ForeColor), startPosition, CSng(0 + (Me.Height / 2) - (szf.Height / 2)))
End Sub
Just replace the line:
Code:
startPosition = szf.Width
with this one:
Code:
startPosition = Me.Width
Please rate helpful ppl's posts. It's the best 'thank you' you can give
I noticed that the control waits for the text to scroll out completely before starting to scroll it again... If the text is long, this may lead to a significant pause...
It would be a good idea to start scrolling a new copy of the text as soon as the old one starts to move out of bounds... I'll try and do that next when I have the time...
Please rate helpful ppl's posts. It's the best 'thank you' you can give