Form Fade In/Out Effect and Notification Window

Introduction

Background processes, applications that run from the tray, and many other types of applications frequently need to show notification/alerts to the user. One of the common examples is Outlook 2003, which shows e-mail notification just over the system tray. This article is about a base class, TransDialog, that derives from Form and adds the fade in/out effect to any form. It also contains a notification form that derives from this TransDialog and shows notification over the system tray.

Using the Code

The project contains the following three forms/classes:

  1. TransDialog—Derives from System.Windows.Forms.Form and adds the fade in effect
  2. Notification—Derives from TransDialog and actually shows the notification
  3. Form1—Driver form used just for the demo

If you are just interested in adding the fade in/out effect, you can derive any TransDialog form as follows.

public class Notification : TransDialog
{
   #region Ctor, init code and dispose
   public Notification()
      : base(true)
   {
      InitializeComponent();
   }
   /* ... */
}

Passing true to the base class will ensure that when you call close on the Notification form, TransDialog will call Dispose and do the cleanup.

How TransDialog Works

TransDialog uses the layering (opacity) property of the form to add the fade in/out effect. At the Form Load event, the opacity of the form is set to 0 (completely transparent or invisible) and a m_clock timer is started. The m_bShowing variable is set to true. The timer is set to tick every 100 ms.

private void TransDialog_Load(object sender, EventArgs e)
{
   this.Opacity = 0.0;
   m_bShowing = true;
   m_clock.Start();
}

On every Tick event, as long as m_bShowing is true, the opacity is increased until is reaches 1 (completely opaque):

if (m_bShowing)
{
   if (this.Opacity < 1)
   {
      this.Opacity += 0.1;
   }
   else
   {
      m_clock.Stop();
   }
}

This gives the fade-in effect.

On the form closing event, the m_bShowing is set to false, the form closing is canceled, and the timer is started again. However, because this time m_bShowing is false, the opacity is decreased until 0 is reached (completely transparent). This gives the fade-out effect.

private void TransDialog_Closing(object sender, CancelEventArgs e)
{
   /* ... */
   m_origDialogResult = this.DialogResult;
   e.Cancel = true;
   m_bShowing = false;
   m_clock.Start();
   /* ... */
}

How Notification Works

The fade-in/out effect on the notification works just by deriving from TransDialog. To show the form at the correct location over the system tray, the following code is used in the load event handler:

private void Notification_Load(object sender, System.EventArgs e)
{
   /* ... */
   int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
   int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
   this.Left = screenWidth - this.Width;
   this.Top = screenHeight - this.Height;
   /* ... */
}


About the Author

Abhinaba Basu

Abhinaba loves coding for the sheer fun of it. He started programming in 1995 with BASIC and then moved through Cobol, Pascal, Prolog, C, C++, VisualBasic and VC++. He received a Bachelor of Technology degree from University of Calcutta in 2001. Abhinaba is originally from the City of Joy, Kolkata in India, but now codes and lives in Noida close to Delhi. His hobby is coding which also happens to be his job. Besides coding he loves traveling.

Downloads

Comments

  • Trist omgivet at kunne ændre tilsluttet strøm til kunderne

    Posted by wanzixiao on 06/04/2013 06:24am

    [url=http://www.nyebeatsbydrdre.350.com/]Nye beats by dr dre[/url] Vi har været i stand til at tilbringe cirka en time med systemet, og vi har helt ærligt komme væk meget imponeret. Enheden føles meget robust, med en stiv metalgitter og soft-touch belægning omkring resten af sit ydre. Det føles meget behageligt at holde i en hånd, og vil nemt passe i en jakkelomme. Faktisk en af vores eneste oprindelige klager er, at den medfølgende regnskabsmæssige skallen ikke efterlader nogen plads til de medfølgende kabler. Alle knapper har en blød, let clicky taktilitet, som også hjælper til sin præmie føler. Brug det i første omgang sammen med en af Beats ‘on-hånd Jamboxes i et kablet A / B sammenligning Jambox kom ud lyde som en forvrænget, rumlende rodet op mod pille – vi havde endda en rep bringe en anden enhed bekræfter, at det var ikke en dud. Hvis det ikke var nok, p-piller også formået at få meget højere, opholder sig temmelig ren (i sammenligning), og uden at rumlen på bordet som den Jambox gjorde meget lidt. Som en tredobbelt-check foranstaltning, senere kom vi op med et lignende resultat med vores in-house-enhed Logitechs $ 99 UE mobil boombox – en højttaler vi finder sammenlignelige med lyd, hvis en smule bedre, end Jambox. [url=http://www.nyebeatsbydrdre.350.com/]Nye beats by dr dre[/url] Uanset om du har brug for netværks personlig brug derhjemme, eller hvis du har brug for at udstyre dit barns skole, som er en meget sød, med henblik på at få en favorit Beats hovedtelefoner nysgerrig, jeg gravede lidt dybere, og jeg gotta jeg ser frem til i alle de basale behov klik her. Faktisk ønsker jeg dig til at bryde det ned til den korte form.Da jeg fik den elskede monster beats hovedtelefoner, og jeg føler meget glad og spændt, men hvad er den virkelige god pleje af det, selv om de nye hovedtelefoner altid vil indtage markedet hurtigt, men når jeg har beats er stadig som ny, tilfredshed aldrig forladt. Vi taler om nogle enkle opførsel om forlængelse af levetiden for headsettet [url=http://www.beatsbydrdredanmark.350.com/]beats by dre danmark[/url] BIII booo din troede involverer let jazz, med essentials involverer normal, god ole ‘, sammen med digitalkameraer sange for dig at lave en ny specifikt eksklusiv lyd. BIII øjeblikket omdefinerer private musik ekspertise til at gøre dine musikernes øretelefoner. Enhver observere, hver eneste nuance, kan optaget med aldrig-hørt-før realistisk look, plus iøjnefaldende design og stil trådløse høretelefoner bestemt ved en ny trompet mundstykke har som en installation vidnesbyrd om den mestre kunsten. Disse former for sædvanligvis er ikke kun de bedste ørepuder vedrørende jazz. Uanset hvad nogen hører, vil BIII sikkert vokset til betragtes som en af dine nuværende all-time musikalske teknologi højder.

    Reply
  • Sólo me preguntaba si ghd de verdad son las mejores planchas para el pelo?

    Posted by hanmeihm on 05/30/2013 04:47pm

    [url=http://www.planchasespanaghdtop.net/]GHD Plancha España[/url] En dos mil organizacin lleg el que haba sido paso a la idea de hacer que el equipo del cabello para siempre. ghd comenzado menor, minimal la verdad es, sin embargo r¢pidamente creci hasta convertirse en la industria del mercado mejor planchita de pelo, as como una empresa conocida en la mayora de las mujeres. Ahora bien, la idea cada ocurri [url=http://www.planchas-ghd.manifo.com/]Planchas Ghd[/url] Lo que significa que, qu¦ es exactamente segundo para conseguir un buen da del pelo Bien es publicitado que buenos das del pelo son en realidad llevar a cabo otra de pelo styler nica forma en que probablemente ser¢n un hervidero este buen da del pelo no es comn. Los buenos das del pelo no planos de hierro comn se vienen en una parada de color marrn brillante va a metal precioso no recibir sol cer¢mica placas de matrcula. Esto ayudar¢ a que este enfoque plancha nica destacan dentro del lugar para llevar. [url=http://www.planchasghdbaratasonline.com/]ghd España[/url] Usando una plancha de pelo GHD Nuevo Negro tambin ayuda en muchas muchas otras maneras. Esto ayuda a evitar que los frizzes molestas que de otro modo hace que el cabello y elimina el brillo del cabello. Su otra ventaja es su tcnica de calentamiento ms rpido, lo que ahorra mucho tiempo para sus usuarios y es tambin uno de los secretos de los que es un elemento muy popular de la alfombra roja de pasarela. Para los salones profesionales tambin es uno de los favoritos por sus diversas caractersticas funcionales como el ajuste de calor auto. Esto tambin es una ventaja notable de las planchas para el pelo GHD.

    Reply
  • Lightweight stylish – Nike Unshackled TR Attack in jump 2013 3 series

    Posted by Tufffruntee on 04/22/2013 02:02pm

    Nike Free TR Stalwart 3 prominent features is to use the new scheme: Nike Free 5 soles improved bending Gouge; new tractor imitate making training more focused when; lighter load, the permeability is stronger, and more fashionable shoe designs not not order shoes [url=http://northernroofing.co.uk/roofins.cfm]nike free run uk[/url] more smug wearing, barefoot training feel, but also more in vogue appearance. Nike Manumitted TR Fit 3 provides supreme lateral perseverance, you can have the legs in the leg during training. Acrid vamp majuscule letters breathable grating, lower soap up's unique map can be [url=http://northernroofing.co.uk/roofins.cfm]nike free uk[/url] seen through it. Lightweight, rugged, piddling bubbles means used by completely occasional seams, more limber, support is stronger. Lack more help, role of a training exercise, foam close in more parts of the need in return flexibility, bubbles loose. Put to use two-ply say nothing moisture wicking fake materials, vapid on your feet, hands maintain feet dry and comfortable. Phylite [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache free[/url] midsole offers lightweight shock sustained, special durability and sedate outsole can do to greatly adjust the comprehensive avoirdupois of the shoe. Qianzhang pods on the outsole and heel-shaped Green rubber enhances the shoe multi-directional purchase on extraordinary surfaces.

    Reply
  • Wow

    Posted by adfdfsdf on 02/05/2013 03:06am

    Your taskbar gave me cancer.

    Reply
  • Few issues

    Posted by Saeed on 10/31/2008 12:30am

    First of all good work 2nd- Once you introduce static control into the form affects controls will not show .. 3rd why not just introduce [CODE} public static void FadeForm(System.Windows.Forms.Form f,bool FadeOut) { float v1 = 1.0F; float v2 = 0.0F; float vd = 0.1F; if (FadeOut) // fadeout { for (float v = v1; v >=v2; v -= vd) { f.Opacity = v; f.Refresh(); } f.Opacity = v2; } else // fadein { for ( float v=v2;v <= v1 ;v += vd) { f.Opacity = v; f.Refresh(); } f.Opacity = v1; } f.Refresh(); } [/CODE} to control the transpanacy . its much easier and simpler.

    Reply
  • looking for C or C++ solution to notification windows

    Posted by yuban on 09/24/2007 08:58pm

    I am trying to find any solution or documentation on the windows api ( if there is one ) for presenting a simple square notification window - such as "Updates are available". Would be nice to add an icon, etc. but even nicer to find documentation on presenting such a feature. Any suggestions ? thx

    Reply
  • Can't get source and demo files

    Posted by javanic on 12/13/2005 11:31am

    Hi. Thanks for the article. I was just what I was looking for, but unfortunately I can't download the demo program or the source code. The links try to open a get_file.php. Any ideas?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Webinar Tuesday, August 26, 2014 1:00 PM EDT Customers are more empowered and connected than ever, and the customer's journey has grown more complex. Their expectations are growing and trust is diminishing as they may interact with multiple brands through web, mobile and social channels. Considering 70% of the buying process in a complex sale is already complete before prospects are willing to engage with a live salesperson -- it's critical to understand your customers and anticipate their needs.* …

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds