Start New Discussion within our Software Development Community

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

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

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

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


double NA;

error C2062: type 'double' unexpected

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.

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.

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) You can make it read-only and change the background color to white (or what ever color it is normally).
2) Application::Exit();

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?

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.
   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;
This article has been dead for over six months. Start a new discussion instead.