-
November 18th, 2011, 11:28 AM
#1
How to make a textbox show the text of a clicked button
Hi! I have just started visual c++ and I am experimenting with a textbox and a bunch of buttons. What I am trying to accomplish is when the user clicks a button the text of the button to be shown in the textbox.
Just like a virtual keyboard so when button "a" is pressed "a" is shown on the textbox. If then button "b" is pressed the textbox will read "ab" etc.
So what's the code I should put on the button click event?
Thanks!
PS. I am using visual studio 2010 c++ windows forms application
-
November 18th, 2011, 12:35 PM
#2
Re: How to make a textbox show the text of a clicked button
In Windows Forms you would use a single Click event handler for all those buttons (see http://www.codeguru.com/forum/showthread.php?t=517485 on how to set that up), and that handler would look somewhat like this:
Code:
void Form1::AllButtonsClickHandler(Object ^sender, EventArgs ^e)
{
textBox1->Text += safe_cast<Button ^>(sender)->Text;
}
BTW, this is not the correct forum section here to post questions about Windows Forms in. The thread I linked to above is in the correct section (C++/CLI). Please post further questions about C++/CLI there.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
November 18th, 2011, 02:14 PM
#3
Re: How to make a textbox show the text of a clicked button
Thank you very much! That's exactly the code I was looking for.
Excuse my luck of knowledge but although I have read your instructions I don't understand how to "attach the handler to the controls" where exactly is the entry field you are talking about?
Thanks again!
-
November 19th, 2011, 12:26 AM
#4
Re: How to make a textbox show the text of a clicked button
To avoid posting even more off-topic stuff in the section here, I've posted my reply to the thread I linked to above, that's already related anyway. Here's the direct link to the reply: http://www.codeguru.com/forum/showthread.php?p=2043268. CU over there...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|