Frage

I am using the input box from visual basic in c# and I couldn't figure out how I know what button has been pressed. The input box return the string that has been written. How I know if the cancel button has been clicked or the OK button?

Thank you very much for the help, I didn't find the answer :)

This is what I tried:

string notineName = Interaction.InputBox("Enter the notice name:", "Enter notice name", "");

If you have another way to do input box ( I wanted to make my own but I don't know how to return what button has been clicked) please write it here.

War es hilfreich?

Lösung 2

As an alternative you could use dialog boxes.

InputDialog dialog = new InputDialog("Caption Here", "Label Text Here", "Default Textbox String");
if (dialog.ShowDialog() == DialogResult.OK)
{
    string result_text = dialog.ResultText;
    // use result_text...
}
else
{
    // user cancelled out, do something...
}

Here an enum result determines what button was selected.

Andere Tipps

If the user clicks Cancel, a zero-length string is returned.

Try having a look at this documentation. MSDN

string a;     
a = Interaction.InputBox("message", "message");
if (a.Length > 0)
{
    comboBox2.Items.Add(a); 
    // ok
}
else
{
    // cancel
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top