4.2 Label
Label is used for multiple purposes like providing instructions and guides to the users, displaying outputs and more. It is different from the TextBox because it is read only, which means the user cannot edit its content at runtime. Using the syntax Label.Text, it can display string as well as numeric data. You can change its text property in the properties window or at runtime by writing an appropriate code.
Example 4.2 Display the output on a Label
Based on Example 4.1, we add two Labels, one is for displaying the text Sum= and the other Label is to display the answer of the Sum. For the first Label, change the text property of the label by typing Sum= over the default text Label1. Further, change its font to bold and its font size to 10. For the second label, delete the default text Label2 and change its font to bold and the font size to 10. Besides that, change its background color to white.
In this program, instead of showing the sum in a message box, we display the sum on the Label.
The Code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click |
*The function Val is to convert text to numeric value. Without using Val, you will see that two numbers are joined without adding them.
The output is as shown in Figure 4.3
Figure 4.3
0 Comments
Thanks for your comment.
i will reply you soon.