Hi guys. Im quite new in coding, so I have a question.
How can I make a button that when I click it, I type something in a textbox right above?
16 replies to this topic
#1
Posted 02 December 2011 - 02:33 PM
|
|
|
#2
Posted 02 December 2011 - 02:41 PM
I assume you mean you want to programmatically set the text in text box.
Inside your button handler:
(Assuming your text box is named "textBox".)
Inside your button handler:
textBox.Text = "Some text.";
(Assuming your text box is named "textBox".)
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#3
Posted 02 December 2011 - 03:33 PM
ok, thanks :D
---------- Post added 12-03-2011 at 12:33 AM ---------- Previous post was 12-02-2011 at 11:57 PM ----------
ok, I did it. :) But when I have 2 buttons like that, the text I had before is getting replaced by the new :S
---------- Post added 12-03-2011 at 12:33 AM ---------- Previous post was 12-02-2011 at 11:57 PM ----------
ok, I did it. :) But when I have 2 buttons like that, the text I had before is getting replaced by the new :S
Edited by Microguy, 02 December 2011 - 03:24 PM.
wrong :P
#4
Posted 03 December 2011 - 01:05 AM
Bump? :)
#5
Posted 03 December 2011 - 02:15 AM
Did you put the code like this after eachother?:
If you did you are replacing text of the textBox.. You could create a new TextBox and put some text into that one..
But right now you're just replacing the text you added first with the one you added after.
You could also use strings for this, Here is an example
This way you can do something like:
textBox.Text = "First Text"; textBox.Text = "Second Text";
If you did you are replacing text of the textBox.. You could create a new TextBox and put some text into that one..
But right now you're just replacing the text you added first with the one you added after.
You could also use strings for this, Here is an example
String s1 = "First Text"; String s2 = "Second Text";
This way you can do something like:
textBox.Text(s1);
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
#6
Posted 03 December 2011 - 02:30 AM
ok, thanks but where should I put it? hope I dont ask too much, Im quite new ;)
richTextBox2.Text = "First text";
richTextBox2.Text = "Second text,";
richTextBox2.Text = "First text";
richTextBox2.Text = "Second text,";
#7
Posted 03 December 2011 - 06:31 AM
Microguy said:
ok, thanks but where should I put it? hope I dont ask too much, Im quite new ;)
richTextBox2.Text = "First text";
richTextBox2.Text = "Second text,";
richTextBox2.Text = "First text";
richTextBox2.Text = "Second text,";
No No.. Im sorry maybe i confused you. I will try to explain why your text boxes don't work properly..
When you first create a Text Box you can give it a text like:
textBox.Text = "Your text here";
But if you after that would add another line putting a new text to the same textBox you are giving the same Text Box a new text..
If you are intrested in one Text Box having the same text all the time you could instead use two different Text Boxes:
textBox1.Text = "This is TextBox one"; textBox2.Text = "This is TextBox two";
And to answear you question where you put this code:
It depends on where you want it.. I recomend try experiment and learn the language you're working with.
If you want to become a good programmer in the future you need to learn what you're doing and know what you're writing in the code.
I won't give you the code in you'r hand but feel free anytime to give me a PM or ask me questions and i will try to help.
Edit:
I read your first post in this thread and i understand that you wanted to open the TextBox when the button was pressed.. (If i understand correctly)
You can do this is you are using Visual C# and your project is based on a windows form:
If you are using the Windows Form for C# then you can double click the button you placed in the form and then it will bring up the button's onClick listener and inside the scope there
you can add the code that tell your program to open the text box.
Hope you understand. :)
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
#8
Posted 03 December 2011 - 10:32 AM
ok.. but that I was looking for is that when I press a button it says for example: "Hi"
and when I press another button it types another world like "you".
What happends with me is that it overwrites eachoter so it wont say "Hi you"
only "Hi" or "you" :crying:
and btw, I think I forgot to say that the text should be in the same richTextBox :)
and when I press another button it types another world like "you".
What happends with me is that it overwrites eachoter so it wont say "Hi you"
only "Hi" or "you" :crying:
and btw, I think I forgot to say that the text should be in the same richTextBox :)
#9
Posted 03 December 2011 - 12:04 PM
I found a complete tutorial about Rich TextBox
Take your time and read it.. It might help: RichTextBox in C#
Take your time and read it.. It might help: RichTextBox in C#
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/
#10
Posted 03 December 2011 - 12:57 PM
thank you very much :)
#11
Posted 05 December 2011 - 06:36 AM
If you want to append (or prepend) text to already existing text, do this:
// To prepend text: textBox.Text = "Pre" + textBox.Text; // To append text: textBox.Text = textBox.Text + "Post";
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#12
Posted 13 December 2011 - 11:34 AM
ok, I have something new.
in a button I have this code:
listBox1.Text = textBox6.Text;
but it doesnt work. it does only work wit "text boxes" but not with list boxes. is it any other code I can use or something I do wrong?
and btw, I need to use a list box.
in a button I have this code:
listBox1.Text = textBox6.Text;
but it doesnt work. it does only work wit "text boxes" but not with list boxes. is it any other code I can use or something I do wrong?
and btw, I need to use a list box.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









