HotDog's Blog

Hotdog (Robert Verpalen) about C# and vb.net

This blog hosted by:
http://blogs.vbcity.com      
  Home :: Syndication  :: Login

SepOctober 2008Nov
SMTWTFS
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Articles

Archives

Topics

CONTACT

Fun but useful linkies

General

VS 2005

Wolfenstein ET

This is a very simple form that shows a message on screen which fades away almost right away (which should be just enough time to get the  message over)

The message is shown in its own thread so that the calling code can continue right away without waiting for the message to disappear

 

Usage:    frmMessage.Show("Your message here");

 

Code:

 

      //the normal usings (windows.forms, system.drawing) +

      //using System.Drawing.Drawing2D;

      public class frmMessage:Form

      {

            private readonly Color

                  foreCol = Color.White,

                  backCol = Color.Navy;

 

            private Font fnt = new Font(FontFamily.GenericSerif,25);

            private frmMessage(ref string message)

            {

                  this.SuspendLayout();

                  this.ControlBox=false;

                  Label l = new Label();

                  l.Text=message;

                  l.Dock=DockStyle.Fill;

                  l.Font=fnt;

                  l.TextAlign=ContentAlignment.MiddleCenter;

                  l.BackColor=backCol;

                  l.ForeColor=foreCol;

                  Controls.Add(l);

 

                  this.StartPosition=FormStartPosition.CenterScreen;

                  this.FormBorderStyle=FormBorderStyle.None;

                  Graphics g = l.CreateGraphics();

                  this.ClientSize=Size.Ceiling(g.MeasureString(message,fnt));

 

                  this.TopMost=true;

                  this.ResumeLayout();

                  new System.Threading.Thread(new System.Threading.ThreadStart(start)).Start();

            }

 

            public static void Show(string message)

            {

                  new frmMessage(ref message);

            }

 

            private void start()

            {

                  this.Show();

                  for(double d = 1 ; d > 0 ; d-=.04)

                  {

                        this.Opacity=d;

                        System.Threading.Thread.Sleep((int)(90*d));

                        Application.DoEvents();

                  }

                  this.Close();

            }

      }

posted on Thursday, August 19, 2004 4:49 AM