"how to set dialogresult yes in c# custom dialog box" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "how to set dialogresult yes in c# custom dialog box" answered properly. Developers are finding an appropriate answer about how to set dialogresult yes in c# custom dialog box related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like how to set dialogresult yes in c# custom dialog box. Enter your desired code related query in the search bar and get every piece of information about C# code related question on how to set dialogresult yes in c# custom dialog box.
how to set dialogresult yes in c# custom dialog box
public void CreateMyForm()
{
// Create a new instance of the form.
Form form1 = new Form();
// Create two buttons to use as the accept and cancel buttons.
Button button1 = new Button ();
Button button2 = new Button ();
// Set the text of button1 to "OK".
button1.Text = "OK";
// Set the position of the button on the form.
button1.Location = new Point (10, 10);
// Set the text of button2 to "Cancel".
button2.Text = "Cancel";
// Set the position of the button based on the location of button1.
button2.Location
= new Point (button1.Left, button1.Height + button1.Top + 10);
// Make button1's dialog result OK.
button1.DialogResult = DialogResult.OK;
// Make button2's dialog result Cancel.
button2.DialogResult = DialogResult.Cancel;
// Set the caption bar text of the form.
form1.Text = "My Dialog Box";
// Define the border style of the form to a dialog box.
form1.FormBorderStyle = FormBorderStyle.FixedDialog;
// Set the accept button of the form to button1.
form1.AcceptButton = button1;
// Set the cancel button of the form to button2.
form1.CancelButton = button2;
// Set the start position of the form to the center of the screen.
form1.StartPosition = FormStartPosition.CenterScreen;
// Add button1 to the form.
form1.Controls.Add(button1);
// Add button2 to the form.
form1.Controls.Add(button2);
// Display the form as a modal dialog box.
form1.ShowDialog();
// Determine if the OK button was clicked on the dialog box.
if (form1.DialogResult == DialogResult.OK)
{
// Display a message box indicating that the OK button was clicked.
MessageBox.Show("The OK button on the form was clicked.");
// Optional: Call the Dispose method when you are finished with the dialog box.
form1.Dispose();
}
else
{
// Display a message box indicating that the Cancel button was clicked.
MessageBox.Show("The Cancel button on the form was clicked.");
// Optional: Call the Dispose method when you are finished with the dialog box.
form1.Dispose();
}
}
Source: docs.microsoft.com
All those coders who are working on the C# based application and are stuck on how to set dialogresult yes in c# custom dialog box can get a collection of related answers to their query. Programmers need to enter their query on how to set dialogresult yes in c# custom dialog box related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to set dialogresult yes in c# custom dialog box for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of how to set dialogresult yes in c# custom dialog box while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "how to set dialogresult yes in c# custom dialog box". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to set dialogresult yes in c# custom dialog box resolved professionally and stay updated to the latest C# updates.