Windows Develop Bookmark and Share   
 index > Windows Forms General > How can I convert from System::Windows::Forms::TextBox^ to "int"
 

How can I convert from System::Windows::Forms::TextBox^ to "int"

The user is going to enter "empNumBox" from a text box. In some point I need to use the amount entered which is of type

"System::Windows::Forms::TextBox^". I would like to use the amount enterdina switch to get the right employee. Unfortunately, thatswitch willaccept only integers.

protected:

private: System::Windows::Forms::TextBox^ empNumBox;

.

.

.


switch (empNumBox)

{
case 1:
{

.
.
}
break;
case 2:

{

.

.
}
break;
case 3:
{

.

.

}
break;
default: MessageBox::Show(" This is an invalid employee number.\n Please try again! ",L" Error ");
}

I may have to use property like this:

property TextBox^ EmpNum
{
TextBox^ get(){return empNumBox; }
void set(TextBox^ p) {empNumBox = p ;}
}

Allen_Press  Friday, September 18, 2009 1:38 AM
It is the "juat" of TextBox.

Hans Passant.
  • Marked As Answer byAllen_Press Saturday, September 26, 2009 12:41 AM
  •  
nobugz  Sunday, September 20, 2009 12:52 AM
Convert the string empNumBox->Text to an int with int::Parse(). Use TryParse() if you don't want to crash the program when the user gets it wrong.

int value = int::Parse(empNumBox->Text);
switch (value) {
// etc...
}


Hans Passant.
nobugz  Friday, September 18, 2009 1:44 AM
I am juat wondering; what is "Text"?
  • Marked As Answer byAllen_Press Saturday, September 26, 2009 12:41 AM
  •  
Allen_Press  Saturday, September 19, 2009 10:22 PM
Thanks it works fine, but what is juat? I was trying to say I "just wondering"!
  • Marked As Answer byAllen_Press Saturday, September 26, 2009 12:41 AM
  •  
Allen_Press  Wednesday, September 23, 2009 12:32 AM
Convert the string empNumBox->Text to an int with int::Parse(). Use TryParse() if you don't want to crash the program when the user gets it wrong.

int value = int::Parse(empNumBox->Text);
switch (value) {
// etc...
}


Hans Passant.
nobugz  Friday, September 18, 2009 1:44 AM
I am juat wondering; what is "Text"?
  • Marked As Answer byAllen_Press Saturday, September 26, 2009 12:41 AM
  •  
Allen_Press  Saturday, September 19, 2009 10:22 PM
It is the "juat" of TextBox.

Hans Passant.
  • Marked As Answer byAllen_Press Saturday, September 26, 2009 12:41 AM
  •  
nobugz  Sunday, September 20, 2009 12:52 AM
Thanks it works fine, but what is juat? I was trying to say I "just wondering"!
  • Marked As Answer byAllen_Press Saturday, September 26, 2009 12:41 AM
  •  
Allen_Press  Wednesday, September 23, 2009 12:32 AM

You can use google to search for other answers

Custom Search

More Threads

• Error: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
• Size a RichTextBox to fit its content
• Web Browser Forms Aspect Ratio
• Setting PrintFileName doesn't suppress Output To dialog
• Highlighting of text in ComboBox with DropDown style
• .NET control does its rendering on mouse over in IE
• Font problem
• How to get more info about port using System.IO.Ports.SerialPort
• BackgroundWorker - How to access variables and controls
• Restarting an application?