BF2Statistics.LoadingForm.ShowScreen C# (CSharp) Method

ShowScreen() public static method

Main calling method. Opens a new instance of the form, and displays it
public static ShowScreen ( Form Parent, bool AllowDrag = false, string WindowTitle = "Loading... Please Wait" ) : void
Parent System.Windows.Forms.Form The parent form, that will be used to center this form over
AllowDrag bool Sets whether this window will be allowed to be moved by the user
WindowTitle string The text in the window title bar
return void
        public static void ShowScreen(Form Parent, bool AllowDrag = false, string WindowTitle = "Loading... Please Wait")
        {
            // Make sure it is currently not open and running.
            if (Instance != null && !Instance.IsDisposed)
                return;

            // Set window position to center parent
            Instance = new LoadingForm();
            Instance.Text = WindowTitle;
            Instance.AllowDrag = AllowDrag;
            double H = Parent.Location.Y + (Parent.Height / 2) - (Instance.Height / 2);
            double W = Parent.Location.X + (Parent.Width / 2) - (Instance.Width / 2);
            Instance.Location = new Point((int)Math.Round(W, 0), (int)Math.Round(H, 0));

            // Display the Instanced Form
            Instance.Show(Parent);

            // Wait until the Instance form is displayed
            while (!Instance.IsHandleCreated) Thread.Sleep(50);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Event fired when the Test button is clicked
        /// </summary>
        private async void TestBtn_Click(object sender, EventArgs e)
        {
            // Build Connection String
            MySqlConnectionStringBuilder Builder = new MySqlConnectionStringBuilder();

            Builder.Server   = Hostname.Text;
            Builder.Port     = (uint)Port.Value;
            Builder.UserID   = Username.Text;
            Builder.Password = Password.Text;
            Builder.Database = DBName.Text;

            // Attempt to connect, reporting any and all errors
            try
            {
                // Show loading form
                LoadingForm.ShowScreen(this, true, "Connecting to MySQL Database...");
                SetNativeEnabled(false);

                // Dont lock up the program
                await Task.Run(() =>
                {
                    using (MySqlConnection Connection = new MySqlConnection(Builder.ConnectionString))
                    {
                        Connection.Open();
                        Connection.Close();
                    }
                });
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message, "Connection Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1,
                                (MessageBoxOptions)0x40000 // Force window on top
                                );
                return;
            }
            finally
            {
                LoadingForm.CloseForm();
                SetNativeEnabled(true);
            }

            // Show success after loading form has been called to close
            MessageBox.Show("Connection Successful!", "Success", MessageBoxButtons.OK,
                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
                            (MessageBoxOptions)0x40000 // Force window on top
                            );
        }
All Usage Examples Of BF2Statistics.LoadingForm::ShowScreen