问题
I'm building a temperature conversion application in Visual Studio for a C++ course. It's a Windows Forms application.
My problem is, when I run the application if I don't have anything entered into either the txtFahrenheit or txtCelsius2 textboxes I get the following error:
"An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll"
The application only works right now when a number is entered into both of the textboxes.
I was told to try and use this:
Double::TryParse()
but I'm brand new to C++ and can't figure out how to use it, even after checking the MSDN library.
回答1:
This will check that the entry in your textbox is convertible to a number.
double val;
bool result = System::Double::TryParse(txtFahrenheit->Text,val);
if (result)
{
//Converted successfully, you can use val
}
else
{
//Error
}
来源:https://stackoverflow.com/questions/12662951/c-windows-forms-application-unhandled-exception-error-when-textbox-empty