Click here to Skip to main content
Click here to Skip to main content

Scrolling Credits Control

By , 14 Jun 2005
 

Sample Image - ScrollingBox_Screenshot.gif

Introduction

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 Near/Center/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 ScrollingBoxText or ScrollingBoxImage which inherits from the ScrollingBoxItem.

scrollingBox1.Alignment = StringAlignment.Center;
scrollingBox1.Padding = new Padding(10, 10, 0, 0);

scrollingBox1.Items.Add(new 
  ScrollingBox.ScrollingBoxText("Hello this is a test"));
scrollingBox1.Items.Add(new 
  ScrollingBox.ScrollingBoxText("Hello this also is a test"));
scrollingBox1.Items.Add(new 
  ScrollingBox.ScrollingBoxImage(Image.FromFile("C:\\image.gif")));
scrollingBox1.Items.Add(new 
  ScrollingBox.ScrollingBoxText("Try having a long string to test wrapping"));
scrollingBox1.Items.Add(new 
  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.

  1. Ensure I set the correct styles for the control.
    SetStyle(ControlStyles.UserPaint
        | ControlStyles.OptimizedDoubleBuffer
        | ControlStyles.AllPaintingInWmPaint, true);
        //ControlStyles.DoubleBuffer if not using .NET v2.0
  2. 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.
    if (clipRectF.IntersectsWith(item.rectF))
  3. 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.

Known Issues

  • 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.

History

  • Uploaded as Visual Studio 2005 Beta 2 solution - 15 June 2005.
  • Uploaded as Visual Studio 2003 solution - 21 June 2005.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

DXNuk
Web Developer
United Kingdom United Kingdom
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberPepsibot20 Aug '11 - 10:15 
+4 for overall usefulness.
+1 for demonstrating how to make a custom control more accessible from within the form designer.
GeneralThanksmemberdooldots12 Nov '09 - 11:11 
You are the best.
QuestionLicense?memberkrisstep113 Nov '09 - 7:57 
Hi,
Saw some other people asking about this but haven't seen an answer. Is there a specific license to use this code?
AnswerRe: License?memberDXNuk3 Nov '09 - 12:18 
Your free to use it in a non commercial sense.
 
My company is about to release a whole new package of controls, of which one is based on this control.
 
Thanks for your interest, David.
 
www.Trustbridge.co.uk
GeneralUsing the code in our commercial productmemberPrakash Buddhiraja11 Mar '09 - 13:07 
Hi,
 
I didn't see any license attached with this article.
Am I free to use this code in our commercial product?
 
Can you please let me know?
 
Thanks,
prakash
GeneralAdd Remove TextmemberBen Harper3 Dec '06 - 20:32 
This looks like it will help me greatly.
However, I think your code would benifit heaps if you were able to remove text and image items in run time.
 
Like if you were to use an imdex when creating the item
scrollingBox1.Items.add("Bla Bla Bla",1)
So you coyld then remove it easily
scrollingBox1.Items.Remove(1)
 
How about it, Im full of good ideas but am not equiped with the knowledge!
You wouldnt be interested in adding this functionality would you?
 
Ha, If so great if not thanks for the good start!!!
Ben
 


 
Ben Harper

GeneralSome Queriesmemberyahyacis17 Nov '06 - 7:52 
How can I stop looping ? I mean, i want to scroll text only once, and i dont want it to to start again.
 
Second question is, is there any way to calculate the total time it will take for complete scroll (taking timer interval into consideration) ?
 
Thanks
Yahya
GeneralText UpdatingmemberMr_Whippy4 Jul '06 - 15:39 
Is it possible to update the text dynamically by removing or adding text?
GeneralRe: Text UpdatingmemberBen Harper3 Dec '06 - 20:17 
Lookin for the same thing, Did you get an answer?
 
Ben Harper

GeneralEmbedded Imagemembersoloforce12 Nov '05 - 5:29 
How could you install and embedded image instead of pulling it from a fixed location?
GeneralRe: Embedded ImagememberLe_MuLoT8 Dec '05 - 5:08 
It`s easy, Big Grin | :-D
 
1. In your project, I suggest that you create a directory named "MyRessources" and put your images files into it.
 
2. Each image file must have the property "BuildAction" set to "Embbeded"
 
3. To get access to your images at runtime, use this function :
 

public static System.Drawing.Image GetEmbeddedImage(string ResourceName)
{
ResourceName = "YOURASSEMBLYNAME.MyResources." + ResourceName;
 
try
{
return new System.Drawing.Bitmap( System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( ResourceName ) );
}
catch
{
throw(new System.Exception("The resource " + ResourceName + " is missing. Maybe the BuildAction isn`t set to Embbeded ?"));
}
}

 
Where ResourceName is the filename of the picture.
 
So, to use with scrollbox :
 

this.scrollingBox1.Items.Add(new ScrollingBox.ScrollingBoxImage(GetEmbeddedImage("MyPicture.gif")));

 
That`s it Wink | ;)
Hope that will help !
QuestionHow to move text Right or Left?memberOmarMallat19 Oct '05 - 18:31 
I read the source code and I found that you ignore the right and the left scrolling. can you update it? and will it scroll all items at same or will be item after item??
any way it's a very nice control.
:-DThanks
 
OmarMallat
QuestionHow to delete item ?sussAnonymous5 Oct '05 - 8:45 
now i know how to add item , but i need to know how remove item orady added .
thank you
AnswerRe: How to delete item ?membersoloforce13 Nov '05 - 6:11 
You can just delete the code that is creating the item.
QuestionLicence?memberhkulten26 Sep '05 - 23:22 
Hi,
 
Very good job!!!
 
Can we use your control into a commercial application?


Thanks.
 
Smile | :)
 
-- modified at 5:24 Tuesday 27th September, 2005
AnswerRe: Licence?memberDXNuk29 Sep '05 - 1:31 
Of course you can, just send me 10% of all sales.
 
Thanks in advance.
 
Dave
Generalvs 2003memberpicazo19 Sep '05 - 9:49 
Hello DXNuk,
 
I was wondering if I could get a copy of the code for VS 2003. Also, since I am rather new at C#, would it be too difficult to make the control scroll horizontally (right to left)? And to read the text and image paths from an xml file?
 
Thanks alot,
 
-----------------
Genaro
 
\\\|
_ _
@ @
_\\
--|
_/
QuestionA simpler way?memberS. Senthil Kumar15 Jun '05 - 7:06 
I did it in a much simpler way by simply moving a transparent label from the bottom to the top of the form in a loop. Worked out quite nicely Smile | :)
 
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
AnswerRe: A simpler way?memberDXNuk15 Jun '05 - 21:43 
Senthil, yes that would be an alternative, but then were's the fun in that?
Plus you would have the overhead of the label control and the image control within a container/user control. This control is lightweight in my opinion.
Thanks for taking the time to look at my code.
Dave

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 15 Jun 2005
Article Copyright 2005 by DXNuk
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid