1.11M Members

Form

 
0
 

How can I give a (display) value to a textbox in form?

 
1
 

It depends.
If this is on Windows (and dot net), you can reach the ->Text property of your textbox.
like: Form1->TextBox1->Text = "hey";

 
0
 

Thanks for the quick answering! Ma next question is?
How can I give a numeric value to a textbox?

 
1
 

Convert the numeric value using the .toString() method.
TextBox1-> Text += iNum.toString();

 
0
 

Thanks, but I also can't find the tonum syntax!

 
0
 

ToNum?

No

ToString();

 
0
 

I would like to convert a textbox to a numeric value.

 
1
 
double.Parse(textBox1->Text);
int.Parse(textBox1->Text);
long.Parse(textBox1->Text);
 
0
 

double NA;
NA=double.Parse(this->A->Text);

error C2062: type 'double' unexpected

 
1
 

http://msdn.microsoft.com/en-us/library/system.double.parse.aspx
Do you need it to be a double?

Are you getting that error on the Parse line (or somewhere else)?
Is that the actual code?

And (my bad)...

double dblTest = double::Parse(this->A->Text);
 
0
 

Thank you for your help. I have successed.
My next question is: Where I have to put user defined functions in a form sulution?
For example I want to define a round() function, but I can't.

 
1
 

It depends.
If the functions specifically have to do with the form, you can put them in the .h file that is the name of the form and create a .cpp file.

You really can JUST bury them in the .h file (just for a test).
If you double-click on the form, Visual studio will take you to the .h file for that form.

If they will be separate classes with particular functions, you should create a new class, put the functions in the class and #include the header file in the module that needs to call the methods in that class.

 
0
 

1. I don't want to give a disabled textbox to give grey color. What can I do?

2. I have put on exit button on my form. What code must contain it?

 
1
 

1) You can make it read-only and change the background color to white (or what ever color it is normally).
2) Application::Exit();

 
0
 

Thanks a lot! I have up-voted your answers. However there are some questions remaind:
1. How do I prevent cursor to go a readonly textbox?
2. Is it passible to use Enter insted of TAB?

 
0
 

1. I would like to put cursor back to the first input textbox.

 
1
 

textBox1->Focus();

 
0
 

Where can I find a description/help abou text1->"methods"?

 
0
 

I have Visual studio 2010 express edition, so I think I have no intellisense.

I have found a usefuul code in help, see below, but I don't know how to implement it to a textbox. Where to put the code, and how, etc? Please help me!

// Boolean flag used to determine when a character other than a number is entered.
private:
   bool nonNumberEntered;

   // Handle the KeyDown event to determine the type of character entered into the control.
   void textBox1_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
   {
      // Initialize the flag to false.
      nonNumberEntered = false;

      // Determine whether the keystroke is a number from the top of the keyboard.
      if ( e->KeyCode < Keys::D0 || e->KeyCode > Keys::D9 )
      {
         // Determine whether the keystroke is a number from the keypad.
         if ( e->KeyCode < Keys::NumPad0 || e->KeyCode > Keys::NumPad9 )
         {
            // Determine whether the keystroke is a backspace.
            if ( e->KeyCode != Keys::Back )
            {
               // A non-numerical keystroke was pressed.
               // Set the flag to true and evaluate in KeyPress event.
               nonNumberEntered = true;
            }
         }
      }
      //If shift key was pressed, it's not a number.
      if (Control::ModifierKeys == Keys::Shift) {
         nonNumberEntered = true;
      }
   }

   // This event occurs after the KeyDown event and can be used to prevent
   // characters from entering the control.
   void textBox1_KeyPress( Object^ /*sender*/, System::Windows::Forms::KeyPressEventArgs^ e )
   {
      // Check for the flag being set in the KeyDown event.
      if ( nonNumberEntered == true )
      {         // Stop the character from being entered into the control since it is non-numerical.
         e->Handled = true;
      }
   }
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: