This is my first submission to CodeProject as I've been keeping all my good controls to myself for years. I've had a change of heart recently and thought I should share my code.
I recently saw a Scrolling Box control on CodeProject and I thought I could improve on its performance, so here's my rendition of it.
Using the code
You can set the alignment of the scrolling text / images to
Far. Padding can be applied on the left and right of the control (top and bottom not used).
Adding text or images is via the Items property by creating a new
ScrollingBoxImage which inherits from the
scrollingBox1.Alignment = StringAlignment.Center;
scrollingBox1.Padding = new Padding(10, 10, 0, 0);
ScrollingBox.ScrollingBoxText("Hello this is a test"));
ScrollingBox.ScrollingBoxText("Hello this also is a test"));
ScrollingBox.ScrollingBoxText("Try having a long string to test wrapping"));
ScrollingBox.ScrollingBoxText("You can use new line switch\nHello"));
The added extra on this control is the ability to scroll backwards or push forward with the mouse, although slightly clumsy in use.
You can also change the font, background color or even have a background image.
Points of Interest
First off, I have written this in Visual Studio 2005 Beta 2, and I guess I'm gonna get a low ranking and a serious flaming because of this. Well, downgrading to a lower version is pretty simple, so if you need an earlier version, post a comment and I'll have to convert it.
Because this control will be constantly updating on the interface we have to reduce flicker to a minimum. I do this in three ways.
- Ensure I set the correct styles for the control.
| ControlStyles.AllPaintingInWmPaint, true);
- Only update the area of the control that needs to be updated, by using clipping (I've not actually done this in this control) and checking where the control needs to be updated.
- Write the bare minimum amount of code in the
OnPaint function that is needed to complete the job, ensuring that all calculations are done else where.
- The mouse is not really in control of the up and down movements, I just call the function that calculates the text / images when the mouse moves.
- No design support for adding text or images.
- Uploaded as Visual Studio 2005 Beta 2 solution - 15 June 2005.
- Uploaded as Visual Studio 2003 solution - 21 June 2005.