hi,
I have a form with 2 panels. when first panel showing form have some defined size and need to show in the middle of the screen. When i click one button the panel hide and the second panel showed(using visible property) and the form is expanded to the work area. When i click another button again i need to show first panel by hiding second panel and the form needs to resize to the defined size . At the same time the form will display in the center of the screen. All are ok except center screen.
The form showed topleft only. Can anyone help me to work around for this / why this is happened? The following is my code
private void Form1_Load(object sender, EventArgs e) { try { this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; this.Height = 315; this.Width = 328; pnl2.Visible = false; pnl1.Visible = true; this.Text = _assemblyDetails.AssemblyTitle + " " + _assemblyDetails.AssemblyVersion; } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK); } }
private void Button1_Click(object sender, EventArgs e) { try { this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; // set position and size to the Form. this.Bounds = Screen.PrimaryScreen.WorkingArea; pnl1.Visible = false; pnl2.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK); } }
private void Button2_Click(object sender, EventArgs e) { this.StartPosition = FormStartPosition.CenterScreen; this.Height = 315; this.Width = 328; pnl1.Visible = true; pnl2.Visible = false; } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK); } }