2
Answers

Problem with Radio Button and Form Navigation

Ask a question
Wyatt70

Wyatt70

19y
2.2k
1
I have a set of radio buttons on a Windows Form. A click of a button is supposed to open a Windows Form. The appropriate form opens when the button is clicked. However, the first click of a button, each click opens the form it's supposed to open plus the previous form that was opened. For example, if I click the first button, Form A opens. I close Form A, and then I click the second button. The second button is only supposed to open Form B, but it opens Form B AND Form A when it is clicked. Here is the code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace DBInfo { /// /// Summary description for Form1. /// public class frmMain : System.Windows.Forms.Form { private System.Windows.Forms.Label lblTitle; private System.Windows.Forms.Label lblSubtitle; private System.Windows.Forms.Label lblButtons; private System.Windows.Forms.RadioButton radSrvNew; private System.Windows.Forms.RadioButton radSrvInfo; private System.Windows.Forms.RadioButton radDB; private System.Windows.Forms.RadioButton radJobHist; private System.Windows.Forms.RadioButton radUserInfo; private System.Windows.Forms.RadioButton radSrvUpdate; private System.Windows.Forms.RadioButton radDBUpdate; private System.Windows.Forms.RadioButton radAnalyze; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public frmMain() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.lblTitle = new System.Windows.Forms.Label(); this.lblSubtitle = new System.Windows.Forms.Label(); this.radSrvNew = new System.Windows.Forms.RadioButton(); this.radSrvInfo = new System.Windows.Forms.RadioButton(); this.radDB = new System.Windows.Forms.RadioButton(); this.radJobHist = new System.Windows.Forms.RadioButton(); this.radUserInfo = new System.Windows.Forms.RadioButton(); this.lblButtons = new System.Windows.Forms.Label(); this.radSrvUpdate = new System.Windows.Forms.RadioButton(); this.radDBUpdate = new System.Windows.Forms.RadioButton(); this.radAnalyze = new System.Windows.Forms.RadioButton(); this.SuspendLayout(); // // lblTitle // this.lblTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.lblTitle.Location = new System.Drawing.Point(16, 16); this.lblTitle.Name = "lblTitle"; this.lblTitle.Size = new System.Drawing.Size(230, 24); this.lblTitle.TabIndex = 0; this.lblTitle.Text = "Technical-Database Services"; // // lblSubtitle // this.lblSubtitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.lblSubtitle.Location = new System.Drawing.Point(16, 48); this.lblSubtitle.Name = "lblSubtitle"; this.lblSubtitle.Size = new System.Drawing.Size(250, 24); this.lblSubtitle.TabIndex = 1; this.lblSubtitle.Text = "Database Information Repository"; // // radSrvNew // this.radSrvNew.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.radSrvNew.Location = new System.Drawing.Point(16, 88); this.radSrvNew.Name = "radSrvNew"; this.radSrvNew.Size = new System.Drawing.Size(270, 20); this.radSrvNew.TabIndex = 3; this.radSrvNew.Text = "Enter A New Server"; this.radSrvNew.CheckedChanged += new System.EventHandler(this.radSrvNew_CheckedChanged); // // radSrvInfo // this.radSrvInfo.Location = new System.Drawing.Point(16, 160); this.radSrvInfo.Name = "radSrvInfo"; this.radSrvInfo.Size = new System.Drawing.Size(270, 20); this.radSrvInfo.TabIndex = 4; this.radSrvInfo.Text = "View Server Information"; this.radSrvInfo.CheckedChanged += new System.EventHandler(this.radSrvInfo_CheckedChanged); // // radDB // this.radDB.Location = new System.Drawing.Point(16, 184); this.radDB.Name = "radDB"; this.radDB.Size = new System.Drawing.Size(270, 20); this.radDB.TabIndex = 5; this.radDB.Text = "View Database Information"; this.radDB.CheckedChanged += new System.EventHandler(this.radDB_CheckedChanged); // // radJobHist // this.radJobHist.Location = new System.Drawing.Point(16, 208); this.radJobHist.Name = "radJobHist"; this.radJobHist.Size = new System.Drawing.Size(270, 20); this.radJobHist.TabIndex = 6; this.radJobHist.Text = "View Job History Information"; this.radJobHist.CheckedChanged += new System.EventHandler(this.radJobHist_CheckedChanged); // // radUserInfo // this.radUserInfo.Location = new System.Drawing.Point(16, 232); this.radUserInfo.Name = "radUserInfo"; this.radUserInfo.Size = new System.Drawing.Size(270, 20); this.radUserInfo.TabIndex = 7; this.radUserInfo.Text = "View User and Login Information"; this.radUserInfo.CheckedChanged += new System.EventHandler(this.radUserInfo_CheckedChanged); // // lblButtons // this.lblButtons.Location = new System.Drawing.Point(16, 72); this.lblButtons.Name = "lblButtons"; this.lblButtons.Size = new System.Drawing.Size(270, 16); this.lblButtons.TabIndex = 8; this.lblButtons.Text = "Choose One Of The Following Options:"; // // radSrvUpdate // this.radSrvUpdate.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.radSrvUpdate.Location = new System.Drawing.Point(16, 112); this.radSrvUpdate.Name = "radSrvUpdate"; this.radSrvUpdate.Size = new System.Drawing.Size(270, 20); this.radSrvUpdate.TabIndex = 9; this.radSrvUpdate.Text = "Update Server Information"; this.radSrvUpdate.CheckedChanged += new System.EventHandler(this.radSrvUpdate_CheckedChanged); // // radDBUpdate // this.radDBUpdate.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.radDBUpdate.Location = new System.Drawing.Point(16, 136); this.radDBUpdate.Name = "radDBUpdate"; this.radDBUpdate.Size = new System.Drawing.Size(270, 20); this.radDBUpdate.TabIndex = 10; this.radDBUpdate.Text = "Update Database Information"; this.radDBUpdate.CheckedChanged += new System.EventHandler(this.radDBUpdate_CheckedChanged); // // radAnalyze // this.radAnalyze.Location = new System.Drawing.Point(16, 256); this.radAnalyze.Name = "radAnalyze"; this.radAnalyze.Size = new System.Drawing.Size(270, 20); this.radAnalyze.TabIndex = 11; this.radAnalyze.Text = "Analyze A SQL Server Instance"; this.radAnalyze.CheckedChanged += new System.EventHandler(this.radAnalyze_CheckedChanged); // // frmMain // this.AutoScaleBaseSize = new System.Drawing.Size(6, 16); this.ClientSize = new System.Drawing.Size(792, 566); this.Controls.Add(this.lblSubtitle); this.Controls.Add(this.lblTitle); this.Controls.Add(this.lblButtons); this.Controls.Add(this.radSrvNew); this.Controls.Add(this.radSrvUpdate); this.Controls.Add(this.radDBUpdate); this.Controls.Add(this.radSrvInfo); this.Controls.Add(this.radDB); this.Controls.Add(this.radJobHist); this.Controls.Add(this.radUserInfo); this.Controls.Add(this.radAnalyze); this.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.Name = "frmMain"; this.Text = "Welcome to the Database Information System"; this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new frmMain()); } private void radSrvNew_CheckedChanged(object sender, System.EventArgs e) { Form frm = new frmEnterServer(); frm.Show(); } private void radSrvUpdate_CheckedChanged(object sender, System.EventArgs e) { Form frm = new frmUpdateServer(); frm.Show(); } private void radDBUpdate_CheckedChanged(object sender, System.EventArgs e) { Form frm = new frmUpdateDatabase(); frm.Show(); } private void radSrvInfo_CheckedChanged(object sender, System.EventArgs e) { Form frm = new frmViewServerInfo(); frm.Show(); } private void radDB_CheckedChanged(object sender, System.EventArgs e) { Form frm = new frmViewDatabaseInfo(); frm.Show(); } private void radJobHist_CheckedChanged(object sender, System.EventArgs e) { Form frm = new frmViewJobInfo(); frm.Show(); } private void radUserInfo_CheckedChanged(object sender, System.EventArgs e) { Form frm = new frmViewUserInfo(); frm.Show(); } private void radAnalyze_CheckedChanged(object sender, System.EventArgs e) { Form frm = new frmAnalyzeServer(); frm.Show(); } } } How do I prevent this from happening?

Answers (2)