I am wondering if c# has build-in input dialog, this dialog only has one(or only a few) text input and OK and Cancel button.
So I don't need to add a new form for such a simple job.
I am wondering if c# has build-in input dialog, this dialog only has one(or only a few) text input and OK and Cancel button.
So I don't need to add a new form for such a simple job.
You can use System.Windows.Forms.MessageBox.Show to create a message box and specify that you only want an Ok
and Cancel
button:
using System.Windows.Forms;
MessageBox.Show("Prompt", "Caption", MessageBoxButtons.OKCancel);
The Show
method returns the button clicked as a System.Windows.Forms.DialogResult:
DialogResult rst = MessageBox.Show("Prompt", "Caption", MessageBoxButtons.OKCancel);
if(rst == DialogResult.OK)
MessageBox.Show("You clicked OK");
If you are asking how to create an input box, then the question has already been asked here What is the C# version of VB.net's InputDialog?, though I would recommend that you create your own version of an input box, because the VBA version is pretty ugly - that way you can also style the input box according to your desire.