Action of a button to a text box?

  • Thread starter Thread starter Byaghy
  • Start date Start date
B

Byaghy

Hi,
I'm quite a newbie with c# and would like to know how to pass a result
to a text-box. Forexample I have a simple form with few textboxes and
a button. When the button is clicked a function calculates something
and the result appears into one of the forms textboxes. How do I do
that?
 
Hi,
I'm quite a newbie with c# and would like to know how to pass a result
to a text-box. Forexample I have a simple form with few textboxes and
a button. When the button is clicked a function calculates something
and the result appears into one of the forms textboxes. How do I do
that?

The textbox has a property, I think it's called ".name".

So, at the button event handler (I trust you know what that is), you
enter a line

TheNameOfYourTextBoxHere.name = "stringFromTheFunction"; //this will
allow your textbox to show the string. You can do the same with a
Label.

You can convert a number to a string any number of ways, such
as .ToString() extension for example.

Doing this from memory, but I think I'm 75% correct or greater.

RL
 
I'm quite a newbie with c# and would like to know how to pass a result
to a text-box. Forexample I have a simple form with few textboxes and
a button. When the button is clicked a function calculates something
and the result appears into one of the forms textboxes. How do I do
that?

Although you're using C#, your question is actually about Windows Forms. I
recommend you ask future questions (since it sounds like you're a complete
beginner with WinForms and are probably focusing on that) in
microsoft.public.dotnet.framework.windowsforms or one of its subgroups.
 
Jeff Johnson said:
Although you're using C#, your question is actually about Windows Forms. I
recommend you ask future questions (since it sounds like you're a complete
beginner with WinForms and are probably focusing on that) in
microsoft.public.dotnet.framework.windowsforms or one of its subgroups.

such as microsoft.public.dotnet.framework.windowsforms.controls, possibly
 
The textbox has a property, I think it's called ".name".
TheNameOfYourTextBoxHere.name = "stringFromTheFunction"; //this will
allow your textbox to show the string. You can do the same with a
Label.

The text box has a property called Name (not .name), and you definitely
don't want to use that property
Doing this from memory, but I think I'm 75% correct or greater.

There is little sense in posting things you don't know. It will just spread
confusion. If you don't know, and you're not willing to try the code first,
then just pass on answering the question.
 
Byaghy said:
Hi,
I'm quite a newbie with c# and would like to know how to pass a result
to a text-box. Forexample I have a simple form with few textboxes and
a button. When the button is clicked a function calculates something
and the result appears into one of the forms textboxes. How do I do
that?

In the designer where you lay out your form, select the button. Double
click on it. The designer will automatically insert an event for the button
click and take you to the code (a method such as button1_Click()). From
there, you can write code such as

textbox1.Text = "new text";
 
Back
Top