Click here to Skip to main content
5,788,212 members and growing! (15,158 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Beginners     Beginner License: The Code Project Open License (CPOL)

Easy to use marquee control for windows form with full designer support.

By Manish Ranjan Kumar

Marque control implementation using .Net 2.0
C# (C# 2.0, C#), .NET (.NET, .NET 2.0), Visual Studio (VS2005, Visual Studio), Dev

Posted: 23 Mar 2008
Updated: 23 Mar 2008
Views: 14,661
Bookmarked: 36 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
24 votes for this Article.
Popularity: 6.38 Rating: 4.63 out of 5
0 votes, 0.0%
1
1 vote, 4.8%
2
1 vote, 4.8%
3
1 vote, 4.8%
4
18 votes, 85.7%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article
MarqueControl_Src

Introduction

This is simple to use Marquee implementation for windows forms using .Net 2.0. This control allows you to customize itself easily and within seconds.

Background

I was looking for Marquee control for window forms. I found a couple but they were very restricted in features and moreover they were very restricted in events.

I decided to write control which will fullfill all of my needs. Further it should be generic enough to be used by others also.

Features

Morquee control has following features

  • Easy to use interface
  • Design time support for control and marquee element
  • ToolTip Support
  • Support of various events
  • Support for multicolor marquee
  • Support for left and right image in marquee element
  • Support for Font in marquee
  • Hover stop feature
  • Marquee element click and double click support
  • Notifies when lap is completed

Using Code

You can use this control in two ways

Via Designer

Use dragdrop feature of visual studio. I will recommend to use the compiled assembly for references. Otherwise if recompiling of assembly is done you will need to restart visual studio.

Add in designer

Use designer of SuperMorquee for to modify the control.

Control designer

Use Properties of control to fine tune the rest properties

Control properties

Use Element collection editor to modify TextElement collection

Element collection editor

Use element designer to set element properties.

Element designer

Via Code

        MarqueControl.Controls.SuperMarquee superMarquee1 = new MarqueControl.Controls.SuperMarquee();

Use following code to add element to the control

                
                TextElement element = new TextElement("Element text");
                element.LeftImageIndex = 0;
                element.RightImageIndex = 1;
                element.IsLink = true;
                element.ForeColor = Color.Red;
                element.Tag = "Tag for element";
                element.Font = new Font("Microsoft Sans Serif", 8.25F);
                element.ToolTipText = "Tool tip for element";
                superMarquee1.Elements.Add(element);   

Alternatively you can use the following code snippent to add new range of elements

                MarqueControl.Entity.TextElement textElement1 = new MarqueControl.Entity.TextElement("TextElement 1");
                MarqueControl.Entity.TextElement textElement2 = new MarqueControl.Entity.TextElement("TextElement 2");
                MarqueControl.Entity.TextElement textElement3 = new MarqueControl.Entity.TextElement("TextElement 3");
                superMarquee1.Elements.AddRange(new MarqueControl.Entity.TextElement[] 
                                                                                        {
                                                                                        textElement1,
                                                                                        textElement2,
                                                                                        textElement3
                                                                                        }
                                                );    

Events Description

ItemClicked

This event is fired when user presses mouse button on the element text area.

            private void superMarquee1_ItemClicked(object sender, ItemClickEventArgs e)
            {
                MessageBox.Show("Item clicked :" + e.Index);
            }    
Note
  1. This event is fired when any button is pressed.
  2. This event is fired only if clicked in text area of the element.

ItemDoubleClicked

This event is fired when user double clicks on the element text area. This has similar features as of ItemClicked.

               private void superMarquee1_ItemDoubleClicked(object sender, ItemClickEventArgs e)
            {
                MessageBox.Show("Item double clicked :" + e.Index);
            }   

LapCompleted

This event is fired when a lap is completed. Applicable only if AutoRewind is set to true. This event can be used in following manner.

                private void superMarquee1_LapCompleted(object sender, System.EventArgs e)
                {
                    MessageBox.Show("Lap completed.");
                }    

BeforeToolTip

This event is fired before tooltip is popped. It supports cancellation of the tooltip being displayed. Apart from cancel feature it supports following

  1. ToolTipText - Used to set ToolTip text.
  2. Location - Used to set location of the tooltip.
  3. Cancel - Used to cancel popup of tooltip.

HitTest and HitTestInfo object

HitTest() function can be used for get information on position of a point relative to the control.

HitTestInfo object contains following properties.

  • Index - Index of the TextElement if point is above element otherwise it is -1.
  • Point - Point where HitTest was performed.
  • Area - HitTestArea at which point is located.

HitTestArea enumeration contains following members

  • Item - Point is above Item. This does not include LeftImage or RightImage
  • LeftImage - Point is above LeftImage of the element.
  • RightImage - Point was hit on RightImage of the element.
  • Strip - Point was hit on Strip.
  • Control - Point is inside the control, but not above Item, LeftImage, RightImage or Strip
  • None - Point is outside the bounds of control.
            HitTestInfo test = superMarquee1.HitTest(PointToClient(MousePosition));
            switch(test.Area)
            {
                case HitTestArea.Item:
                    break;
                case HitTestArea.LeftImage:
                    break;
                case HitTestArea.RightImage:
                    break;
                case HitTestArea.Strip:
                    break;
                case HitTestArea.Control:
                    break;
                case HitTestArea.None:
                    break;
            }    

Alternatively you can create new instance of the HitTestInfo class in following manner

            HitTestInfo test = new HitTestInfo(superMarquee1, PointToClient(MousePosition));
            switch(test.Area)
            {
                case HitTestArea.Item:
                    break;
                case HitTestArea.LeftImage:
                    break;
                case HitTestArea.RightImage:
                    break;
                case HitTestArea.Strip:
                    break;
                case HitTestArea.Control:
                    break;
                case HitTestArea.None:
                    break;
            }    

ToolTip and ToolTipData object

To use tooltip Property AutoToolTip must be set to true. Predefined tooltip can be used or dynamic tooltip can also be used using event BeforeToolTip.

Following code snippet illustrates how to add dynamic tooltip to the element.

            private void superMarquee1_BeforeToolTip(object sender, GenericCancelEventArgs <ToolTipData> tArgs)
            {
                tArgs.Value.ToolTipText = "New dynamic text based on condition.";
            }    

Code below will illustrates how to change position of the tooltip being displayed.

            private void superMarquee1_BeforeToolTip(object sender, GenericCancelEventArgs<ToolTipData> tArgs)
            {
                tArgs.Value.Location = new Point(tArgs.Value.Location.X + 10, tArgs.Value.Location.Y + 20);
            }    

This is how you tooltip display can be cancelled.

            private void superMarquee1_BeforeToolTip(object sender, GenericCancelEventArgs tArgs)
            {
                tArgs.Cancel = true;
            }    

Points of Interest

SuperMarquee

Properties

  • HoverStop - Gets or sets that marquee will be running or not if mouse hover is there.
  • AutoRewind - Gets or sets on completion of one round of marquee it will start again or not.
  • Elements - Gets list of the TextElement associated with the control.
  • Running - Gets or sets whether marquee is running or not.
  • AutoToolTip - Gets or sets whether tool tip will be shown autometically.
  • ImageList - Gets or sets the ImageList associated with the component.
  • StripColor - Gets or sets the Color of the stripe. Enable ShowStrip for displaying the strip.
  • ShowStrip - Gets or sets that strip will be shown or not.
  • MarqueeSpeed - Gets or sets the Speed of the marquee. Maximum speed is 999 and minimum speed is 1.

Events

  • ItemClicked - Fired when Item is clicked.
  • ItemDoubleClicked - Fired when Item is double clicked.
  • LapCompleted - Fired when lap is completed.
  • BeforeToolTip - Fired when ToolTip is about to display.

Methods

  • HitTest() - Performs the HitTest.
  • Reset() - Reset the control.
  • ResetMorquee() - Reset the marquee of control.
  • StartMarquee() - Starts marquee.
  • StopMarquee() - Stops marquee.

TextElement

Properties

  • Text - Text displayed in this element.
  • ForeColor - Text color of the element.
  • IsLink - Indicates whether the element will be displayed as a link or not.
  • Font - Font of this element.
  • Tag - User data associated with the element.
  • LeftImageIndex - Left image index of the image to be displayed.
  • RightImageIndex - Right image index of the image to be displayed.
  • ToolTipText - Text displayed in this element.

Methods

  • Reset() - Reset the element.

Known Issues

  • At high speed flickering is there.
  • Element jumping is sometimes not proper.

History

24 March 2008 : Initial Draft of the control.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Manish Ranjan Kumar


Graduate from IIT Kharagpur.
Working with Windows forms application for last 2.5 Years.
Currently working with Proteans Software Solutions Bangalore.
Occupation: Software Developer (Senior)
Company: Proteans
Location: India India

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
GeneralIDE crashesmemberZerus Zocker2:06 29 Nov '08  
Questiongoodmemberameer008620:52 28 Nov '08  
GeneralGreat WorkmemberAhmedA12:55 12 Oct '08  
AnswerRe: Great WorkmemberManish Ranjan Kumar1:35 13 Oct '08  
QuestionDatabasememberTcode4:47 19 Sep '08  
Generalerror in visual studio 2008 [modified]memberpolgei4:04 27 Jul '08  
AnswerRe: error in visual studio 2008memberManish Ranjan Kumar1:36 13 Oct '08  
GeneralVista CompatabilitymemberMember 467023510:53 27 May '08  
GeneralRe: Vista CompatabilitymemberManish Ranjan Kumar5:17 28 May '08  
GeneralTest Program gives an error with Visual Studio 2008membergokhansumer20:35 31 Mar '08  
AnswerRe: Test Program gives an error with Visual Studio 2008memberManish Ranjan Kumar0:36 1 Apr '08  
GeneralCool!!!memberprashudupa3:15 28 Mar '08  
GeneralCannot get the marquee to startmemberphanie23:59 27 Mar '08  
AnswerRe: Cannot get the marquee to startmemberManish Ranjan Kumar1:18 28 Mar '08  
AnswerRe: Cannot get the marquee to startmemberManish Ranjan Kumar1:19 28 Mar '08  
GeneralLooks goodmemberDerek Bartram14:17 24 Mar '08  
GeneralVery CoolmemberF16I7:06 24 Mar '08  
GeneralNice!memberRavi Bhavnani3:53 24 Mar '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Mar 2008
Editor:
Copyright 2008 by Manish Ranjan Kumar
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project