5 Replies - 13542 Views - Last Post: 24 August 2008 - 01:20 PM Rate Topic: -----

#1 aclark17   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 71
  • Joined: 18-June 08

c++ win forms integer input

Posted 24 August 2008 - 10:31 AM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: c++ win forms integer input

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5612
  • View blog
  • Posts: 14,686
  • Joined: 18-April 07

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.

:)
Was This Post Helpful? 0
  • +
  • -

#3 aclark17   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 71
  • Joined: 18-June 08

Re: c++ win forms integer input

Posted 24 August 2008 - 11:31 AM

View PostMartyr2, 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.

:)

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;
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5612
  • View blog
  • Posts: 14,686
  • Joined: 18-April 07

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^.

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!" :snap:
Was This Post Helpful? 0
  • +
  • -

#5 aclark17   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 71
  • Joined: 18-June 08

Re: c++ win forms integer input

Posted 24 August 2008 - 01:19 PM

View PostMartyr2, 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^.

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!" :snap:


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...
Was This Post Helpful? 0
  • +
  • -

#6 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1