SIGN UP MEMBER LOGIN:    
ARTICLE

Scrolling Text Marquee Control

Posted by Sam Hobbs Articles | Windows Forms C# January 13, 2010
The following article is a simple sample of a scrolling text marquee control for a Windows Forms application.
Reader Level:
 

The HTML MARQUEE Element creates a scrolling text marquee, but there is not an equivalent provided by Microsoft for desktop applications. The following is a simple sample of a scrolling text marquee control for a Windows Forms application.

The control uses a Timer object. For each timer tick, the text to scroll is updated by moving the current first character to the last character position. This causes the affect of the text continually scrolling. The text is written directly to the control's window using TextRenderer.DrawText.

To use the control, simply add the UserControl to a form and then during execution, such as in the form's constructor, set the UserControl's Text property to the text to scroll. If you are unfamiliar with the use of UserControls, then simply add the ScrollingTextControl.cs file in the attached file to the project, then build the project to ensure that Visual Studio sees it as a UserControl, then drag the ScrollingTextControl from the Toolbox onto the form.

The following is the UserControl.
public partial class ScrollingTextControl : UserControl
{
    Timer MarqueeTimer = new Timer();
    String CurrentText = "Scrolling text";
    String OurText;

    public ScrollingTextControl()
    {
        InitializeComponent();
        MarqueeTimer.Interval = 150;
        MarqueeTimer.Enabled = true;
        MarqueeTimer.Tick += new EventHandler(MarqueeUpdate);
    }

    public int Interval
    {
        get { return MarqueeTimer.Interval; }
        set { MarqueeTimer.Interval = value; }
    }

    public override String Text
    {
        get { return OurText; }
        set { OurText = value; CurrentText = OurText; }
    }

    private void ScrollingTextControl_Paint(object sender, PaintEventArgs e)
    {
        TextRenderer.DrawText(e.Graphics, CurrentText, Font, ClientRectangle,
            SystemColors.ControlText);
    }

    void MarqueeUpdate(object sender, EventArgs e)
    {
        CurrentText = CurrentText.Substring(1) + CurrentText[0];
        Invalidate();
    }
}
 

Login to add your contents and source code to this article
share this article :
post comment
 

For ASP use the ASP control for a marquee tag in HTML; you don't need anything from this article for ASP applications.

Posted by Sam Hobbs May 03, 2011

in Literal control i am using marquee when page opens its running marquee when i am selecting location (for change marquee text) its not working

Posted by neelesh masih May 03, 2011

How can i change the text color and also how can i set the time interval a little bit slow so that after completion of the given text it should come again

Posted by Dorababu M Dec 10, 2010
Posted by hossein javidian Apr 28, 2010

I am sorry, but I am not familiar with "some problem". What is that? As far as I know, my sample does not do "some problem", whatever that is.

Posted by Sam Hobbs Apr 06, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor