Change image opacity at runtime in windows application
this is code how to change image opacity at runtime in windows application of .net
Changing image opacity at runtime
Hello friends here is the code for changing image opacity at runtime for which you have to use two timer controls. At first timer control tick event we are checking if opacity of form is greater than 1 or less than 0 then multiply tv variable by -1 make the opacity more.On timer2 tick event we are setting current form background image
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private float tv;
private int pno;
public Form1()
{
tv = 5;
InitializeComponent();
pno = 1;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.Opacity >= 1 || this.Opacity <= 0)
{
tv = tv * -1;
}
this.Opacity += tv / 100;
}
private void timer2_Tick(object sender, EventArgs e)
{
this.BackgroundImage = Image.FromFile("c:\\" + pno + ".jpg");
}
}
}