Here is a control I created to create a scrolling marquee effect.
Printable View
Here is a control I created to create a scrolling marquee effect.
Thank you for your CodeBank submission.
Per this CodeBank policy, I have edited your attachment and removed all compiled code.
We welcome and appreciate all entries into our Codebank, but ask that source code only be included with anything attached.
Thank you.
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.
Yeah, feel free to use it, and change it however you wish.:D
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?
Do you have a sample of the text you are "scrolling"?
It's "Loading your personal data..." I think.
I didn't have an issue with the above text. I will do further testing.Quote:
Originally Posted by obi1kenobi
You can take a look at the OnPaint event. That is what handles the drawing of the text.
Try switching the direction the text is scrolling once or twice. I'll have a look at the OnPaint method.
I fixed the issue. Have a look at the original OnPaint:
Just replace the line: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
with this one:Code:startPosition = szf.Width
Code:startPosition = Me.Width
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...