开发者

Labels and events!

I have a question? How can I wire up an button in a winform to take an input from a label, and put it in a text box to display the result?

I'm confused!

I have 4 labels... I want to be able to have people put input into the labels click the update button, and then display the results in the textbox below.

Any help?开发者_如何学C Thank you!


OK so basic outline of what you need to do:

1) Go to the toolbox and put textbox(es) on the form for the user to type in.

2) Add at least one label for your output text

3) Add a Button

4) Select each item on the form, go to its properties (f4) and set the Name property for each one to something that you can remember (this is how you'll reference the controls in your code)

5) Double click on the submit button. This will open up an "Event Handler" for Button.Click, which means the code you write will run when someone clicks the button.

6) Write the C# code to do what you want. For instance, this takes the contents of a textbox (tbInput.Text) and copies it to the label text (lblOutput.Text):

lblOutput.Text = tbInput.Text;

Hope this helps...if not, read the first 3 or 4 chapters of any beginning C# book.


You don't put input input into label, you do that in a TextBox. A label is a as its name implies a "label" (fixed unmodifiable text).


Most simply, create a method to handle the Click event of the button, bind it in.

Inside this method get the text from the labels, and then update the textbox with the input.


.NET standard Labels are not the controls you are looking for. Labels are just that...text labels that do not provide for text input. What you want is a TextBox, which you will be able to find in the Visual Studio Toolbox.

If you want the look and feel of a Label, but the functionality of a TextBox, you can modify the TextBox properties accordingly (border style, background color, etc).

Drop a Button onto your form, and from the Designer if you double-click the button, a _Click event handler will be generated in your source file from which you can implement the code to do whatever it is you want to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜