Marquee Label Demo : Marquee Label « Components « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Components » Marquee LabelScreenshots 
Marquee Label Demo
Marquee Label Demo


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
        private MarqueeLabel marqueeLabel1;
        private System.Windows.Forms.GroupBox GroupBox1;
        private System.Windows.Forms.Label Label2;
        private System.Windows.Forms.TrackBar tbInterval;
        private System.Windows.Forms.Label Label1;
        private System.Windows.Forms.TrackBar tbAmount;

      public Form1() {
            InitializeComponent();
            
      }
        private void tbAmount_ValueChanged(object sender, EventArgs e)
        {
            marqueeLabel1.ScrollPixelAmount = tbAmount.Value;
        }

        private void tbInterval_ValueChanged(object sender, EventArgs e)
        {
            marqueeLabel1.tmrScroll.Interval = tbInterval.Value;
        }

        private void InitializeComponent()
        {
            this.GroupBox1 = new System.Windows.Forms.GroupBox();
            this.Label2 = new System.Windows.Forms.Label();
            this.tbInterval = new System.Windows.Forms.TrackBar();
            this.Label1 = new System.Windows.Forms.Label();
            this.tbAmount = new System.Windows.Forms.TrackBar();
            this.marqueeLabel1 = new MarqueeLabel();
            this.GroupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.tbInterval)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.tbAmount)).BeginInit();
            
            this.SuspendLayout();
            // 
            // GroupBox1
            // 
            this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.GroupBox1.Controls.Add(this.Label2);
            this.GroupBox1.Controls.Add(this.tbInterval);
            this.GroupBox1.Controls.Add(this.Label1);
            this.GroupBox1.Controls.Add(this.tbAmount);
            this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.GroupBox1.Location = new System.Drawing.Point(22177);
            this.GroupBox1.Name = "GroupBox1";
            this.GroupBox1.Size = new System.Drawing.Size(336132);
            this.GroupBox1.TabIndex = 6;
            this.GroupBox1.TabStop = false;
            // 
            // Label2
            // 
            this.Label2.Location = new System.Drawing.Point(1276);
            this.Label2.Name = "Label2";
            this.Label2.Size = new System.Drawing.Size(8023);
            this.Label2.TabIndex = 6;
            this.Label2.Text = "Scroll Interval:";
            // 
            // tbInterval
            // 
            this.tbInterval.Location = new System.Drawing.Point(9672);
            this.tbInterval.Maximum = 500;
            this.tbInterval.Minimum = 10;
            this.tbInterval.Name = "tbInterval";
            this.tbInterval.Size = new System.Drawing.Size(22845);
            this.tbInterval.TabIndex = 5;
            this.tbInterval.TickFrequency = 10;
            this.tbInterval.Value = 100;
            this.tbInterval.ValueChanged += new System.EventHandler(this.tbInterval_ValueChanged);
            // 
            // Label1
            // 
            this.Label1.Location = new System.Drawing.Point(1220);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(8023);
            this.Label1.TabIndex = 4;
            this.Label1.Text = "Scroll Amount:";
            // 
            // tbAmount
            // 
            this.tbAmount.Location = new System.Drawing.Point(9616);
            this.tbAmount.Maximum = 20;
            this.tbAmount.Name = "tbAmount";
            this.tbAmount.Size = new System.Drawing.Size(22845);
            this.tbAmount.TabIndex = 3;
            this.tbAmount.Value = 10;
            this.tbAmount.ValueChanged += new System.EventHandler(this.tbAmount_ValueChanged);
            // 
            // marqueeLabel1
            // 
            this.marqueeLabel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.marqueeLabel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255))))((int)(((byte)(255))))((int)(((byte)(192)))));
            this.marqueeLabel1.Font = new System.Drawing.Font("Verdana"26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.marqueeLabel1.ForeColor = System.Drawing.Color.Navy;
            this.marqueeLabel1.Location = new System.Drawing.Point(-27);
            this.marqueeLabel1.Name = "marqueeLabel1";
            this.marqueeLabel1.tmrScroll.Interval = 100;
            this.marqueeLabel1.Size = new System.Drawing.Size(384156);
            this.marqueeLabel1.TabIndex = 7;
            this.marqueeLabel1.Tag = "";
            this.marqueeLabel1.DisplayText = "This scrolls!";
            // 
            // MarqueeTestForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(381322);
            this.Controls.Add(this.marqueeLabel1);
            this.Controls.Add(this.GroupBox1);
            this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "MarqueeTestForm";
            this.Text = "MarqueeTestForm";
            this.GroupBox1.ResumeLayout(false);
            this.GroupBox1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.tbInterval)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.tbAmount)).EndInit();
            
            this.ResumeLayout(false);

        }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}

  public class MarqueeLabel : Control
  {
    public string DisplayText;
    public int ScrollPixelAmount = 10;
    public System.Windows.Forms.Timer tmrScroll;
    private int position = 0;

    public MarqueeLabel()
    {
      this.tmrScroll = new System.Windows.Forms.Timer(new System.ComponentModel.Container());
      this.tmrScroll.Tick += new System.EventHandler(this.tmrScroll_Tick);
      this.Size = new System.Drawing.Size(360104);
        
            DoubleBuffered = true;
            ResizeRedraw = true;

      tmrScroll.Enabled = true;
        }

    private void tmrScroll_Tick(object sender, System.EventArgs e)
    {
      position += ScrollPixelAmount;
      Invalidate();            
    }

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
            base.OnPaint(e);
      if (position > Width)
      {
        position = -(int)e.Graphics.MeasureString(DisplayText, Font).Width;
      }
      e.Graphics.DrawString(DisplayText, Font, new SolidBrush(ForeColor), position, 0);
    }
    }
           
       
Related examples in the same category
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.