1,105,578 Community Members

Form

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
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";

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
1
 

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

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
0
 

ToNum?

No

ToString();

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
1
 
double.Parse(textBox1->Text);
int.Parse(textBox1->Text);
long.Parse(textBox1->Text);
Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

error C2062: type 'double' unexpected

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
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);
Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
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.

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
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();

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
1
 

textBox1->Focus();

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
1
 

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.

Member Avatar
NatherLaci
Newbie Poster
22 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: