My application is hardware based so it have connection in first form's contructor called myform. i want to display splash screen until loads myform in background. application in c sharp. after splash screen login will display.
Asked
Active
Viewed 54 times
0
-
You sound like you are asking someone to do it for you. You should show that you have put some effort into it. http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx – Kard Nails Feb 27 '15 at 08:14
-
I am beginner. I just want some help or guidance – Akshay Khade Feb 27 '15 at 08:20
-
Google is your friend: tinyurl.com/nw3b9qe – Kard Nails Feb 27 '15 at 10:43
-
i thought here i'll found some technical answers. but not bad – Akshay Khade Feb 27 '15 at 11:06
1 Answers
0
Check my SimpleSplash implementation.
public sealed class SplashForm<T> : Form
where T : Form
{
public SplashForm()
{
SuspendLayout();
Size = new Size(350, 100);
StartPosition = FormStartPosition.CenterScreen;
FormBorderStyle = FormBorderStyle.None;
var lblMessage = new Label
{
Location = new Point(10, 10),
Text = "loading..."
};
Controls.Add(lblMessage);
ResumeLayout(false);
PerformLayout();
LoadMainForm();
}
private async void LoadMainForm()
{
Form instance = null;
await Task.Run(() =>
{
//--get the main form type
var firstFormType = GetType().GenericTypeArguments.First();
//--create the instance
instance = Activator.CreateInstance(firstFormType) as Form;
});
if (instance == null)
throw new InvalidOperationException("form initialization error");
OnMainFormLoaded(instance);
}
public event EventHandler<Form> MainFormLoaded;
private void OnMainFormLoaded(Form formInstance)
{
EventHandler<Form> handler = MainFormLoaded;
if (handler != null)
handler(this, formInstance);
}
}
The below code is a sample form implementation:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
Thread.Sleep(Environment.TickCount%1500); //--simulate variables initialization
}
}
You need to make some adjustments in application entry point.
internal static class Program
{
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form mainFormInstance = null;
var splash = new SplashForm<MainForm>();
splash.MainFormLoaded +=
(s, e) =>
{
mainFormInstance = e;
splash.Dispose();
};
Application.Run(splash);
Application.Run(mainFormInstance);
}
}
I hope it helps.
denys-vega
- 3,522
- 1
- 19
- 24