Click here to Skip to main content
13,143,985 members (35,411 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 13 Sep 2013

Custom Popup Fade-in Window in C#/Winform/.NET

, 13 Sep 2013
Rate this:
Please Sign up or sign in to vote.
In this tip, I'll show you how I make a replacement for tooltip


Sometimes, we come across the situation where we need to put a button, a picture, or a listview on a tooltip.

Building a form is how I make it, rather than use tooltip.

Using the Code

To display an image, simply set the tag attributes :

button1.Tag = Image.FromFile("img.jpg");
PopUpWindow.ClassPopUp pop = new PopUpWindow.ClassPopUp();
pop.Initialize(button1, true, "This Is A Test!");

The background color and forecolor can be modified:

pop2.Initialize(label1, false, "This is another test!", 
new System.Drawing.Size(320, 240), Color.Black, Color.White);    

The fade-in/out effect is very simple:

  1. Override the OnLoad event of the form:
    protected override void OnLoad(EventArgs e)
                this.Location = MousePosition;
                if (!DesignMode)
                    fadeIn = true;
                    Opacity = 0;
                    timer_fade.Enabled = true;
  2. Override the OnClosing event of the form:
    protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
               if (e.Cancel)
               if (Opacity > 0)
                   fadeIn = false;
                   timer_fade.Enabled = true;
                   e.Cancel = true;
  3. The timer is set like this:
    timer_fade.Interval = 50;
    timer_fade.Tick += timer_fade_Tick;
  4. In the timer_tick event, change the opacity of the form:
    void timer_fade_Tick(object sender, EventArgs e)
                if (fadeIn)
                    Opacity += (timer_fade.Interval / 166.0);
                    timer_fade.Enabled = (Opacity < 1.0);
                    fadeIn = (Opacity < 1.0);
                    Opacity -= (timer_fade.Interval / 166.0);
                    if (this.Opacity > 0)
                        timer_fade.Enabled = true;
                        timer_fade.Enabled = false;
  5. To show an image, set the background image of the form.
  6. To show text, use CreateGraphics and Drawstring.
    (Do not use Drawstring before the opacity is 1.0.)
  7. You can create a form on which you put whatever you like. Don't forget to set the FormBorderStyle to None.

For more, please check the source.

This is my first time posting a tip here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sean Chung
Software Developer
China China
No Biography provided

You may also be interested in...

Comments and Discussions

BugUnhandled Exception can occur! Pin
Member 1125783923-Nov-14 13:10
memberMember 1125783923-Nov-14 13:10 
GeneralMy vote of 2 Pin
herves16-Sep-13 0:33
memberherves16-Sep-13 0:33 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 13 Sep 2013
Article Copyright 2013 by Sean Chung
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid