Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to fade c# form

Timer t1 = new Timer();

private void Form1_Load(object sender, EventArgs e)
{
            Opacity = 0;      //first the opacity is 0

            t1.Interval = 10;  //we'll increase the opacity every 10ms
            t1.Tick += new EventHandler(fadeIn);  //this calls the function that changes opacity 
            t1.Start(); 
}

void fadeIn(object sender, EventArgs e)
{
            if (Opacity >= 1)  
                t1.Stop();   //this stops the timer if the form is completely displayed
            else
                Opacity += 0.05;
}
Comment

how to fade c# form

private void main_FormClosing(object sender, FormClosingEventArgs e)
{
      e.Cancel = true;    //cancel the event so the form won't be closed

      t1.Tick += new EventHandler(fadeOut);  //this calls the fade out function
      t1.Start();

      if (Opacity == 0)  //if the form is completly transparent
          e.Cancel = false;   //resume the event - the program can be closed

}

void fadeOut(object sender, EventArgs e)
{
      if (Opacity <= 0)     //check if opacity is 0
      {
          t1.Stop();    //if it is, we stop the timer
          Close();   //and we try to close the form
      }
      else
          Opacity -= 0.05;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to fill model enum with bradio button asp razor 
Csharp :: convert string into float C# 
Csharp :: Send Hotmail, Outlook, Office365 Email using SMTP C# .NET 
Csharp :: how to add gravity without rb in unity 
Csharp :: access label from another class c# 
Csharp :: c# .net core entity framework one to many 
Csharp :: encrypt password easiest way in web app .net 
Csharp :: minimum of three numbers 
Csharp :: c# tell if a class is a child or the class itself 
Csharp :: Unity upload image to project 
Csharp :: wpf StrokeDashArray 
Csharp :: unity for loop array 
Csharp :: caesar cipher in C# 
Csharp :: cread 2-dimensional array in c# 
Csharp :: print text c# unity 
Csharp :: enum in combobox wpf 
Csharp :: dctionary literal c# 
Csharp :: C# Async Function simple 
Csharp :: SQLite Parameters 
Csharp :: unity GetNestedComponentsInChildren 
Csharp :: C# Console font 
Csharp :: reflection get enum value C# 
Csharp :: csv to xml using xmldocument c# 
Csharp :: asp.net web forms 
Csharp :: unity set cursor position 
Csharp :: wpf app transparent background with blurred image affect 
Csharp :: check .net installing 
Csharp :: c#, get a embedded resx file 
Csharp :: deferred rendering unity 
Csharp :: how to change argument of function in f# 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =