Click here to Skip to main content
15,888,610 members
Articles / Programming Languages / C#
Article

FakeFlash Title

Rate me:
Please Sign up or sign in to vote.
3.09/5 (20 votes)
28 Jan 20042 min read 82.2K   2.5K   57   24
Animated title component.

Sample Image - FFTitle.jpg

Introduction

This component is for demonstrating a simple animation with the Graphics class from .NET. This component can be used in a wizard or main form to display the name of your application more cute. It's easy to modify and use.

Graphics on .NET

In .NET, there are many class and interfaces for paint and manipulation of graphics and images. I'm a web master, and I love Flash. But I like C#, and I tried to find a way to get some effects into C# that I used to do in ActionScript, like draw with random points and colors, and I got it. The Graphics Classes provide many useful methods for development in GDI+.

How it works

Well, this component, uses a timer to update and invalidate a Draw event (OnPaint) from the main form. This event draws the main gradient, the vertical bars and the title. This is the OnPaint event, read the comments to understand every line:

C#
protected override void OnPaint(PaintEventArgs e) 
{
  base.OnPaint(e); /* Support to draw the component */
  Rectangle sqb = new System.Drawing.Rectangle(0,0,this.Width,
    this.Height); /* Create a rectangle for allow draw the gradient */
  LinearGradientBrush lgbb = new 
    System.Drawing.Drawing2D.LinearGradientBrush(sqb, 
    this.startColor, this.endColor, 0, true);   
  lgbb.GammaCorrection = true; /* Add correction to the converge 
                           of color, to make the fade more cute =P */
  Rectangle sqs = new System.Drawing.Rectangle(0,0,10,this.Height);
  LinearGradientBrush lgbs = new 
    System.Drawing.Drawing2D.LinearGradientBrush(sqb, 
    this.BackColor, Color.Transparent, 90, true);
  lgbs.GammaCorrection = true;
  e.Graphics.FillRectangle(lgbb, 0, 0, this.Width, this.Height);
  Random rnd = new 
    Random(unchecked((int)DateTime.Now.Ticks)); /* Create a random number */
  for (int i=0; i < this.bars; i++)
  {
    int rnm1 = rnd.Next(this.Width-20);
    int rnm1a = rnd.Next(10)+10;
    e.Graphics.FillRectangle(lgbs, rnm1, 0, 
      rnm1a, this.Height); /* With the random numbers draw the bars */
  }
  e.Graphics.SmoothingMode = 
     System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 
     /* Add Antialias to linew more soft */

  if(this.moving) 
  /* When MarqueeOn is fire this bool allow to the text scroll */
  {
    switch(this.direction)
    {
      case 0:
        MoveVertical();
        break;
      case 1:
        MoveHorizontal();
        break;
      default:
        MoveHorizontal();
        break;
    }
  }
  e.Graphics.DrawString(this.Text, this.Font, 
      new SolidBrush(Color.Gray), 
      (this.xstr+1), (this.ystr+1)); /* Draw the text */
  e.Graphics.DrawString(this.Text, this.Font, 
      new SolidBrush(this.ForeColor), 
      this.xstr, this.ystr); /* Draw the shadow text */
}

Source Code

Some points for explanation are:

  • ControlStyles: with this I can make the control repaint itself by Resize events. With DobleBuffer, you can allow the form to use two graphic buffers, one for the next paint, and one for the actual paint. This style needs the UserPaint and WmPaint, becauses this allow repaint without the OS request.
    C#
    SetStyle(ControlStyles.ResizeRedraw, true);
    SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint 
                 | ControlStyles.AllPaintingInWmPaint, true);
    UpdateStyles();
  • Brushes: the Brush class, in special, LinearGradientBrush gives you the power for filling shapes and strings into a panel. You can query the .NET docs about the other brushes, like PathGradientBrush or SolidBrush.
    C#
    LinearGradientBrush lgbb = new 
      System.Drawing.Drawing2D.LinearGradientBrush(sqb, 
      this.startColor, this.endColor, 0, true);

Updates

02/02/2004

Fixed Marquee and Tester.

29/01/2004

  • Added support to Marquee-style to the text.
  • Added drop shadow to text.
  • Added speed properties to choose the bar's speed.
  • Gamma correction to the gradients.

Something else

Well, it's my first article, I tried to make my best. My mother language isn't English (it's Spanish), for this reason, forgive me about bad spelling =D.

Try the demo file, I hope to update this component soon.

Thanks.

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


Written By
Web Developer
Mexico Mexico
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralLicensing inquiry Pin
2twotango9-Feb-09 10:47
2twotango9-Feb-09 10:47 
GeneralRe: Licensing inquiry Pin
hxxbin15-Feb-09 13:04
hxxbin15-Feb-09 13:04 
GeneralBottom to Up Pin
svmilky12-May-06 15:40
svmilky12-May-06 15:40 
QuestionHow I can work with marquee text Only? Pin
mailhn27-Feb-05 6:08
mailhn27-Feb-05 6:08 
AnswerRe: How I can work with marquee text Only? Pin
mailhn8-Apr-05 22:59
mailhn8-Apr-05 22:59 
GeneralMarquee Pin
hollandridderkerk15-Aug-04 22:04
hollandridderkerk15-Aug-04 22:04 
GeneralRe: Marquee Pin
Craig Eddy2-Nov-06 4:52
Craig Eddy2-Nov-06 4:52 
Generallook nice but i cant start it Pin
unimate319-Jun-04 13:26
unimate319-Jun-04 13:26 
GeneralRe: look nice but i cant start it Pin
hxxbin10-Jun-04 4:23
hxxbin10-Jun-04 4:23 
GeneralRe: look nice but i cant start it Pin
unimate3110-Jun-04 6:20
unimate3110-Jun-04 6:20 
GeneralTime based movement Pin
NetDevKing24-May-04 7:29
NetDevKing24-May-04 7:29 
GeneralRe: Time based movement Pin
hxxbin24-May-04 7:58
hxxbin24-May-04 7:58 
GeneralYou can display Flash itself in a C# form Pin
pdelmundo27-Apr-04 11:53
pdelmundo27-Apr-04 11:53 
GeneralLooks so Cool! But in the designer... Pin
androboy18-Mar-04 20:01
androboy18-Mar-04 20:01 
GeneralRe: Looks so Cool! But in the designer... Pin
hxxbin19-Mar-04 9:43
hxxbin19-Mar-04 9:43 
QuestionMarquee text? Pin
Andrew Allen29-Jan-04 18:21
Andrew Allen29-Jan-04 18:21 
AnswerRe: Marquee text? Pin
hxxbin2-Feb-04 4:09
hxxbin2-Feb-04 4:09 
AnswerFix it Pin
hxxbin2-Feb-04 6:31
hxxbin2-Feb-04 6:31 
GeneralAmazing control! Pin
malharone27-Jan-04 6:55
malharone27-Jan-04 6:55 
GeneralRe: Amazing control! Pin
hxxbin27-Jan-04 7:22
hxxbin27-Jan-04 7:22 
GeneralNice idea Pin
SoTTo13-Jan-04 13:15
SoTTo13-Jan-04 13:15 
GeneralRe: Nice idea Pin
hxxbin14-Jan-04 6:29
hxxbin14-Jan-04 6:29 
GeneralFakeFlash Title Pin
Shato11-Jan-04 4:05
Shato11-Jan-04 4:05 
GeneralRe: FakeFlash Title Pin
hxxbin12-Jan-04 4:30
hxxbin12-Jan-04 4:30 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.