VB.Net: Exercices
//
Ecrire le code VBNet qui permet de réaliser l’interface suivante:

Code Source
Public Class Form1
Dim TypeOpération As String
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
RadioButton1.Checked = True
TypeOpération= « + »
‘Button2.Enabled = False
txtN1.TextAlign = HorizontalAlignment.Right
txtN2.TextAlign = HorizontalAlignment.Right
txtResult.TextAlign= HorizontalAlignment.Right
End Sub
Private SubButton1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txtN1.Clear()
txtN2.Clear()
txtResult.Clear()
txtN1.Focus()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim Nbr1, Nbr2 As Double
Dim Nbr3 As String = « »
Nbr1 = Val(txtN1.Text)
Nbr2 = Val(txtN2.Text)
Select Case TypeOpération
Case « + »
Nbr3 = Nbr1 + Nbr2
Case « -«
Nbr3 = Nbr1 – Nbr2
Case « * »
Nbr3 = Nbr1 * Nbr2
Case « / »
Nbr3 = Nbr1 / Nbr2
Case « V »
Label2.Text = « V »
If txtN1.Text = « » Then
If txtN2.Text = « » Then
Nbr3 = Format(Math.Sqrt(Nbr1), « 0.0000 »)
Nbr3 &= vbTab & Format(Math.Sqrt(Nbr2), « 0.0000 »)
Else
Nbr3 = Format(Math.Sqrt(Nbr1), « 0.0000 »)
End If
Else
If txtN2.Text = « » Then
Nbr3 = Format(Math.Sqrt(Nbr2), « 0.0000 »)
End If
End If
End Select
txtResult.Text= Nbr3
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
TypeOpération = « + »
Label2.Text = « + »
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
TypeOpération= « -«
Label2.Text = « -«
End Sub
Private Sub
RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
TypeOpération = « * »
Label2.Text = « * »
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
TypeOpération= « / »
Label2.Text = « / »
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
TypeOpération= « V »
Label2.Text = « V »
End Sub
Private Sub txtN1_TextChanged(sender As Object, e As EventArgs) Handles txtN1.TextChanged
If txtN1.Text = « » Then
Button2.Enabled = False
Else
If txtN2.Text = « » Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End If
End Sub
Private Sub txtN2_TextChanged(sender As Object, e As EventArgs) Handles txtN2.TextChanged
If txtN2.Text = « » Then
Button2.Enabled = False
Else
If txtN1.Text = « » Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End If
End Sub
End Class
