Im trying to create an interface to allow for a user input of integers, all I can seem to find on in the toolbox are textboxes. Is there a way I can create somthing similar to a textbox that will support integers, also I am very new to win forms and am not sure perfrom arithmetic operations on integers or which header file to include.
c++ win forms integer inputintegers in textbox?
Page 1 of 1
5 Replies - 13542 Views - Last Post: 24 August 2008 - 01:20 PM
Replies To: c++ win forms integer input
#2
Re: c++ win forms integer input
Posted 24 August 2008 - 10:49 AM
There are three ways to do this.
1) You can create a textbox and setup an event that evaluates the key pressed to see if the character is a number and only let those pass through to the textbox.
2) You can inherit from the textbox and force it to only accept numbers.
3) Use the "maskedtextbox" control that should be in your toolbox. This is a textbox that can have a mask (aka forced pattern) in which you can say is only numbers.
Choices 1 and 3 is rather easy for a beginner and choice 2 is an intermediate level option. It is up to you how you want to do it but typically I would go choice 1 and choice 3, but choice 2 is something you could do too.
It is up to you. Try out the maskedtextbox first and change its "mask" property and see if that will suffice and if not you can just evaluate the keys pressed in a textbox event and only let numbers through.
1) You can create a textbox and setup an event that evaluates the key pressed to see if the character is a number and only let those pass through to the textbox.
2) You can inherit from the textbox and force it to only accept numbers.
3) Use the "maskedtextbox" control that should be in your toolbox. This is a textbox that can have a mask (aka forced pattern) in which you can say is only numbers.
Choices 1 and 3 is rather easy for a beginner and choice 2 is an intermediate level option. It is up to you how you want to do it but typically I would go choice 1 and choice 3, but choice 2 is something you could do too.
It is up to you. Try out the maskedtextbox first and change its "mask" property and see if that will suffice and if not you can just evaluate the keys pressed in a textbox event and only let numbers through.
#3
Re: c++ win forms integer input
Posted 24 August 2008 - 11:31 AM
Martyr2, on 24 Aug, 2008 - 10:49 AM, said:
There are three ways to do this.
1) You can create a textbox and setup an event that evaluates the key pressed to see if the character is a number and only let those pass through to the textbox.
2) You can inherit from the textbox and force it to only accept numbers.
3) Use the "maskedtextbox" control that should be in your toolbox. This is a textbox that can have a mask (aka forced pattern) in which you can say is only numbers.
Choices 1 and 3 is rather easy for a beginner and choice 2 is an intermediate level option. It is up to you how you want to do it but typically I would go choice 1 and choice 3, but choice 2 is something you could do too.
It is up to you. Try out the maskedtextbox first and change its "mask" property and see if that will suffice and if not you can just evaluate the keys pressed in a textbox event and only let numbers through.

1) You can create a textbox and setup an event that evaluates the key pressed to see if the character is a number and only let those pass through to the textbox.
2) You can inherit from the textbox and force it to only accept numbers.
3) Use the "maskedtextbox" control that should be in your toolbox. This is a textbox that can have a mask (aka forced pattern) in which you can say is only numbers.
Choices 1 and 3 is rather easy for a beginner and choice 2 is an intermediate level option. It is up to you how you want to do it but typically I would go choice 1 and choice 3, but choice 2 is something you could do too.
It is up to you. Try out the maskedtextbox first and change its "mask" property and see if that will suffice and if not you can just evaluate the keys pressed in a textbox event and only let numbers through.
alright ya, im playing with the maskedtextbox and still I cannot complile:
int x;
x=maskedTextBox1->text;
maskedTextBox2->text=x;
which is a step toward what im tying to do ...IE int x=textBox1->text;int y=textBox2->text;textBox3->text=x+y;
#4
Re: c++ win forms integer input
Posted 24 August 2008 - 12:12 PM
Datatypes my good man, you can't just dump a String^ value right into int variables and then back to String^.
Here is how you can do this. Enjoy!
"At DIC we be maskedtextbox converting code ninjas... we too are also masked. What a co-ink-a-dink!"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// Convert each masktextbox to integer values
int x = Convert::ToInt32(maskedTextBox1->Text);
int y = Convert::ToInt32(maskedTextBox2->Text);
// Add the values together and convert back to a string for our textbox display
textBox1->Text = Convert::ToString(x + y);
}
Here is how you can do this. Enjoy!
"At DIC we be maskedtextbox converting code ninjas... we too are also masked. What a co-ink-a-dink!"
#5
Re: c++ win forms integer input
Posted 24 August 2008 - 01:19 PM
Martyr2, on 24 Aug, 2008 - 12:12 PM, said:
Datatypes my good man, you can't just dump a String^ value right into int variables and then back to String^.
Here is how you can do this. Enjoy!
"At DIC we be maskedtextbox converting code ninjas... we too are also masked. What a co-ink-a-dink!"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// Convert each masktextbox to integer values
int x = Convert::ToInt32(maskedTextBox1->Text);
int y = Convert::ToInt32(maskedTextBox2->Text);
// Add the values together and convert back to a string for our textbox display
textBox1->Text = Convert::ToString(x + y);
}
Here is how you can do this. Enjoy!
"At DIC we be maskedtextbox converting code ninjas... we too are also masked. What a co-ink-a-dink!"
AWESOME..now for my next question, how would I extract just the integers from a string in a textBox and assign a combo of integers and chars to a textBox.
IE: textBox1="2x^5";textBox2="3x^5"; how will extract the integers for comparision and then assign a textBox 5x^5...
#6
Re: c++ win forms integer input
Posted 24 August 2008 - 01:20 PM
edit: never mind
This post has been edited by KYA: 24 August 2008 - 01:25 PM
Page 1 of 1

New Topic/Question
Reply



MultiQuote



|