Hello,
I am building an application and on a button click, a new dialog form is built and has three buttons. When the user clicks on the Next button (DialogResult.Y es), I do not want the form to close. However, I am having trouble with the form not closing. Can you provide any help? Here is the method that I currently have in place.
I am building an application and on a button click, a new dialog form is built and has three buttons. When the user clicks on the Next button (DialogResult.Y es), I do not want the form to close. However, I am having trouble with the form not closing. Can you provide any help? Here is the method that I currently have in place.
Code:
private void manualEntry(object sender, EventArgs e) { System.Windows.Forms.Button next = new System.Windows.Forms.Button(); next.Text = "Next"; next.Location = new System.Drawing.Point(10, 70); next.DialogResult = DialogResult.Yes; System.Windows.Forms.Button okay = new System.Windows.Forms.Button(); okay.Text = "Complete"; okay.Location = new System.Drawing.Point(105, 70); okay.DialogResult = DialogResult.OK; System.Windows.Forms.Button cancel = new System.Windows.Forms.Button(); cancel.Text = "Cancel"; cancel.Location = new System.Drawing.Point(200, 70); cancel.DialogResult = DialogResult.Cancel; System.Windows.Forms.TextBox sID = new System.Windows.Forms.TextBox(); sID.Location = new System.Drawing.Point(60, 10); sID.Size = new System.Drawing.Size(215, 50); System.Windows.Forms.TextBox sName = new System.Windows.Forms.TextBox(); sName.Location = new System.Drawing.Point(60, 40); sName.Size = new System.Drawing.Size(215, 50); System.Windows.Forms.Label lblID = new System.Windows.Forms.Label(); lblID.Font = new System.Drawing.Font(lblID.Font.Name, 12, lblID.Font.Style, lblID.Font.Unit); lblID.Location = new System.Drawing.Point(5, 10); lblID.Text = "ID:"; System.Windows.Forms.Label llblName = new System.Windows.Forms.Label(); llblName.Font = new System.Drawing.Font(llblName.Font.Name, 12, llblName.Font.Style, llblName.Font.Unit); llblName.Location = new System.Drawing.Point(5, 40); llblName.Text = "Name:"; Form dialog = new Form(); dialog.Size = new System.Drawing.Size(300, 140); dialog.MaximizeBox = false; dialog.MinimizeBox = false; dialog.FormBorderStyle = FormBorderStyle.FixedSingle; dialog.StartPosition = FormStartPosition.CenterScreen; dialog.Text = "Manual Student Entry"; dialog.AcceptButton = okay; dialog.CancelButton = cancel; dialog.Controls.Add(next); dialog.Controls.Add(okay); dialog.Controls.Add(cancel); dialog.Controls.Add(sID); dialog.Controls.Add(sName); dialog.Controls.Add(lblID); dialog.Controls.Add(llblName); dialog.ShowDialog(); if (dialog.DialogResult == DialogResult.OK) { if (sID.Text == "" | sName.Text == "") { MessageBox.Show("A student id and student name must be entered to be processed,"); return; } else { oXL = new Microsoft.Office.Interop.Excel.Application(); oXL.Visible = false; // oWK = oXL.Workbooks.Open(path + "\\" + fileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); oWK = oXL.Workbooks.Open(path + "\\" + fileName); oWS = (Microsoft.Office.Interop.Excel.Worksheet)oWK.Worksheets[1]; oWS.Cells[i, 1] = sID.Text.ToString(); oWS.Cells[i, 2] = sName.Text.ToString(); i++; oWK.Save(); oWK.Close(); oXL.Workbooks.Close(); } } if (dialog.DialogResult == DialogResult.Yes) { dialog.DialogResult = DialogResult.None; } } }
Comment