I have a splash screen that i am using it when i am loading data from a smart card because it takes about 35 seconds to get the data my loading screen have a white backcolor and i set the TransparencyKey to white color to make the screen transparent. and it works fine but after about 6 seconds the back color turns to black Here is the code of the loading screen:
partial class LoadingForm : Form
{
int tickcount = 0;
public bool CloseIt = false;
public string Message = "من فضلك إنتظر قليلا ...";
public Point LocationPoint;
public LoadingForm()
{
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.DoubleBuffer, true);
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.DoubleBuffer, true);
LocationPoint = new Point();
LocationPoint.X = -300;
LocationPoint.Y = -300;
lblMessage.Text = Message;
}
private void LoadingForm_Load(object sender, EventArgs e)
{
Left = LocationPoint.X;
Top = LocationPoint.Y;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (Created)
{
if (tickcount++ == 1)
{
LocationPoint.X = Screen.PrimaryScreen.Bounds.Width / 2 - 240;
LocationPoint.Y = Screen.PrimaryScreen.Bounds.Height / 2 - 140;
lblMessage.Text = Message;
Left = LocationPoint.X;
Top = LocationPoint.Y;
Width = 480;
Height = 185;
}
if (CloseIt)
{
pictureBox1.Image = null;
Close();
Application.ExitThread();
}
}
}
private void LoadingForm_FormClosing(object sender, FormClosingEventArgs e)
{
timer1.Stop();
timer1.Dispose();
}
}
And this is the class that create a thread to run the form on it:
public class LoadingProgress
{
LoadingForm frm = new LoadingForm();
string Message = "من فضلك إنتظر قليلا ...";
Thread th;
public void StartProgress()
{
th = new Thread(new ThreadStart(ShowForm));
if (frm == null)
frm = new LoadingForm();
frm.Message = Message;
th.Start();
}
public void Set_Message(string msg)
{
Message = msg;
frm.Message = Message;
}
void ShowForm()
{
frm.ShowDialog();
frm.Dispose();
frm = null;
if (th.ThreadState == ThreadState.Running)
th.Abort();
}
public void Stop()
{
frm.CloseIt = true;
}
public void Set_Position(System.Drawing.Point p)
{
frm.LocationPoint = p;
}
}