Frage

I'm using an InputBox from the Visual Basic Library and I need to determine which button has been selected by the end user. With the InputBox you can only grab the Entered Value by the user, I also need to detect if they hit Ok or Cancel.

Has anyone tried doing this before?

I know I could create a new form and do it that way, but wondering there's a workaround for this??

string answer =  Interaction.InputBox("Question","Title","");

I can determine if the user has input anything by the answer.length, but I need to know whether they hit "Cancel" or "Ok" after typing something as I need to abort on "Cancel".

War es hilfreich?

Lösung

You can't, except for checking the string length.

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

So if you want to be able to distinguish between a click of the cancel button and the fact the user just entered an empty string, you're out of luck.

But there are plenty of custom implementations out there, like this one on codeplex, which will return a DialogResult.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top