HotDog's Blog

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

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

JulAugust 2004Sep
SMTWTFS
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234

Articles

Archives

Topics

CONTACT

Fun but useful linkies

General

VS 2005

Wolfenstein ET

Thursday, August 19, 2004 #

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 @ 4:49 AM