Hey guys,

I have a splash screen I'm loading here:

private void main_Form_Load(object sender, EventArgs e)
        {
            //Load Splash Screen
            this.Hide();
            Form_Splash form_Splash = new Form_Splash();
            form_Splash.Owner = this;
            form_Splash.Show();
            System.Threading.Thread.Sleep(3000);

            form_Splash.progressBar_splash.Value = 10;
            form_Splash.label_Process.Text = "Checking Authentication...";
            System.Threading.Thread.Sleep(2000);

            // Create the context for the principal object. 
            PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "REG");

            // Retrieve the group principal object for the group you need.
            GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(ctx, "Domain Admins");

            // Check to see if this user is a member of the "Administrators" group.
            bool isMember = UserPrincipal.Current.IsMemberOf(groupPrincipal);

            if (!isMember)
            {
                form_Splash.label_Process.Text = "Authentication Failed!";
                MessageBox.Show("You do not have the appropriate permissions - Some controls may be disabled.  If you feel you have received this notification in error, contact your system administrator.", "Authentication Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                try
                {
                    form_Splash.progressBar_splash.Value = 30;
                    form_Splash.label_Process.Text = "Initializing SQL Connections...";
                    System.Threading.Thread.Sleep(2000);

                    //sql connection string
                    string cs = "Data Source=REG-PENTREE1\\SQLEXPRESS;Initial Catalog=reg_checkout;Integrated Security=SSPI";
                    conn = new SqlConnection(cs);
                    form_Splash.progressBar_splash.Value = 50;
                    System.Threading.Thread.Sleep(2000);

                    //open sql connection
                    form_Splash.label_Process.Text = "Openning SQL Connections...";
                    conn.Open();

                    form_Splash.label_Process.Text = "Starting...";
                    form_Splash.progressBar_splash.Value = 80;
                    System.Threading.Thread.Sleep(2000);

                    // cmd = new SqlCommand("UPDATE Laptops SET isCheckedOut=1 WHERE name='pen-laptop1'", conn);
                    // cmd.ExecuteNonQuery();
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    Console.WriteLine("Source: " + ex.Source);
                    Console.WriteLine("Exception Message: " + ex.Message);
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine("Source: " + ex.Source);
                    Console.WriteLine("Exception Message: " + ex.Message);
                }
            }
            form_Splash.progressBar_splash.Value = 100;
            System.Threading.Thread.Sleep(2000);
            form_Splash.Close();   

            // TODO: This line of code loads data into the 'reg_checkoutDataSet1.Laptops' table. You can move, or remove it, as needed.
            this.laptopsTableAdapter.FillByCheckedIn(this.reg_checkoutDataSet1.Laptops);
          
        }

The screen loads, and the progress bar moves fine, but the label and image on the splash screen never update. Any ideas why this is happening?

I've attached a screenshot of the splash screen.

I try to keep my splash screens on seperate threads for things like this. However you may be able to add an Application.DoEvents(); before your thread.sleep statements to allow all the events / painting to process.

Kenny

Actually I would place them after updating the text / image itself. I didn't look too closely at your code.

Kenny

Call form_Splash.Refresh() method.

private void Form1_Load(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.Show();
            f.Owner = this;
               
            f.BeginInvoke(new Action(()=>{
                f.label1.Text = "Hello";
                f.label2.Text = "Hi";
                
                f.progressBar1.Maximum = 100;
                f.progressBar1.Minimum = 1;
                f.Refresh();
                for (int i = 1; i <= 100; i++)
                {
                     
                    f.progressBar1.Value = i;

                    System.Threading.Thread.Sleep(100);
                }
            }));
            
  }

I like adatapost's recomendation better in this case. Much lighter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.