Some of the controls of Visual Basic.Net tool box are explored in this chapter. VB.Net has different types of controls using which you can write applications at ease.

Text Box:Enables the user to enter text, and provides multiline editing and password character masking.
Label:Provides Run time information or descriptive text for a control.
Label:This control raises an event when the user clicks it.

Following program is written to accept two numbers, to calculate the average of entered two numbers, to clear the contents of the text boxes and to quit the form when the user desires to do so. The application is executed and resultant screen is shown in Fig. 1.
The following example has all the three controls placed in the form namely text box,label and button.

Public Class Form1
Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculate.Click
'The following lines calculate the average of values entered 'in txtnum1 and txtnum2 and displays on txtaverage
Me.txtaverage.Text = (Val(txtnum1.Text) + Val(txtnum2.Text)) / 2
End Sub

Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
'clearing the screen
Me.txtnum1.Text = ""
Me.txtnum2.Text = ""
Me.txtaverage.Text = ""
End Sub

Private Sub btnquti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnquti.Click
'quitting the program
End
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.txtnum1.Text = ""
Me.txtnum2.Text = ""
Me.txtaverage.Text = ""
End Sub
End Class

Following program is written to implement a simple calculator. The program is Fig. 2 shows the implementation of simple calculator. The program is executed and resultant screen is shown in Fig. 2.

Public Class Form2
Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click
Me.txtResult.Text = Val(Me.txtOperand1.Text) + Val(Me.txtOperand2.Text)
Me.Label1.Text = "+" End Sub

Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click
Me.txtResult.Text = Val(Me.txtOperand1.Text) - Val(Me.txtOperand2.Text)
Me.Label1.Text = "-"
End Sub

Private Sub btnMultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiplication.Click
Me.txtResult.Text = Val(Me.txtOperand1.Text) * Val(Me.txtOperand2.Text)
Me.Label1.Text = "*"
End Sub
Private Sub btnDivision_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivision.Click
Me.txtResult.Text = Val(Me.txtOperand1.Text) / Val(Me.txtOperand2.Text)
Me.Label1.Text = "/"
End Sub

Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
Me.txtOperand1.Text = ""
Me.txtOperand2.Text = ""
Me.Label1.Text = ""
Me.txtResult.Text = ""
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
End Class


Check Box: This control enables the user select or clears the associated option. Some, all or none of the choices in a group may be selected.
Following example written to display greetings in four different languages. When you select a specific language and click the ‘Go’ button then the greeting in the corresponding language is displayed. In the Fig. 3 all the languages are selected so the greeting is displayed in all the languages. Public Class Form4
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Clic
k If Me.chkHindi.Checked = True Then
Label2.Visible = True
Else
Label2.Visible = False
End If
If Me.chkKannada.Checked = True Then
Label3.Visible = True
Else
Label3.Visible = False
End If
If Me.chkTamil.Checked = True Then
Label4.Visible = True
Else
Label4.Visible = False
End If
If Me.chkMalayalam.Checked = True Then
Label5.Visible = True
Else
Label5.Visible = False
End If
End Sub
Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
End
End Sub
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False
Label5.Visible = False
End Sub
End Class

Adding new Forms to the project << Previous
Next >>Option Button,List

Our aim is to provide information to the knowledge seekers. 


comments powered by Disqus








Footer1