We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,001 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Form

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

2
Contributors
40
Replies
2 Weeks
Discussion Span
1 Year Ago
Last Updated
41
Views
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

ToNum?

No

ToString();

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
double.Parse(textBox1->Text);
int.Parse(textBox1->Text);
long.Parse(textBox1->Text);
thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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

error C2062: type 'double' unexpected

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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);
thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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.

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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?

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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?

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

textBox1->Focus();

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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

NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox_properties.aspx

If you are using Visual Studio 2008 or 2005, you can are the commands in IntelliSense.
...or hit F1 if you have msdn installed.

...otherwise, just use the msdn website.

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

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;
      }
   }
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.3591 seconds using 2.82MB