.
In Depth Banner
Skip Navigation Links

Select your preferred language

The clock tick event handler

    private void TickHandler(object sender, EventArgs e)

    {

 

      COLORREF cr=new COLORREF();

      cr.Color=Color.White;

      _currentTick++;

      if(_alpha<255 && _currentTick<60)

      {

        //clock fades in;

        _alpha+=32;

        if(_alpha>255)

          _alpha=255;

 

        Win32Methods.SetLayeredWindowAttributes(

            this.Handle, //The handle to the window

            cr,          //the COLORREF for the colour key

           (byte)_alpha,(int)LWADefs.LWA_COLORKEY | (int)LWADefs.LWA_ALPHA); //The flags to set, both alpha and colour key

      }

      else if(_currentTick>60)

      {

        //clock fades out

        _alpha-=32;

        if(_alpha<0)

          _alpha=0;

        Win32Methods.SetLayeredWindowAttributes(this.Handle,cr,(byte)_alpha,(int)LWADefs.LWA_COLORKEY | (int)LWADefs.LWA_ALPHA);

        if(_alpha==0)

          this.Hide();

      }

      Win32Methods.RedrawWindow(this.Handle,IntPtr.Zero,IntPtr.Zero,(int)RDWDefs.RDW_INVALIDATE | (int)RDWDefs.RDW_NOERASE | (int)RDWDefs.RDW_INTERNALPAINT);

    }

 

As you can see, this method uses a considerable amount of interop to perform it's function. This page explains the interop used in this project.

Return to the article

Copyright © Bob Powell 2000-.  All rights reserved.