Sunteți pe pagina 1din 53

Tél.

: 066950863

Programmation é vènementielle
évènementielle
1
ELhaidaoui@hotmail.com
Interfaces graphiques avec VB.NET

2
comment créer l'interface utilisateur ?
Comment créer une fenêtre?
Menu Projet, Ajouter un formulaire Windows, cliquer sur WindowsForm, une fenêtre ‘Form1’ apparaît. On a bien crée

une fenêtre avec la classe WindowsForms.Form (En fait on a crée une Classe 'Form1')
Comment ajouter un bouton?

Cliquer sur ‘Boite à Outils’ à gauche , bouton WindowsForms, puis bouton ‘Button’,cliquer dans Form1, déplacer le

curseur sans lâcher le bouton, puis lâcher le bouton : un bouton apparaît.


Comment ajouter un label?

Un label est un contrôle qui permet d’afficher un texte.

Modifier les propriétés de l'objet.

3
4
5
TP 1: Réaliser une application qui fait les calculs suivants :

6
7
8
Private Sub btnega_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnega.Click
Nbre2 = Val(Res.Text)
Select Case TypeOpération
Case 1
Nbre3 = Nbre1 / Nbre2
Case 2
Nbre3 = Nbre1 * Nbre2
Case 3
Nbre3 = Nbre1 + Nbre2
Case 4
Nbre3 = Nbre1 - Nbre2
End Select
Res.Text = Str(Nbre3)
End Sub
Private Sub btnplu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnplu.Click
'Addition
Nbre1 = Val(Res.Text)
TypeOpération = 3
End Sub
Private Sub btnneg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnneg.Click
Nbre1 = Val(Res.Text)
TypeOpération = 4
End Sub
Private Sub btnDiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDiv.Click
Nbre1 = Val(Res.Text)
TypeOpération = 1
End Sub
Private Sub btnmul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmul.Click
Nbre1 = Val(Res.Text)
TypeOpération = 2
End Sub
Private Sub CE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CE.Click
Res.Clear()
Nbre1 = 0 9
End Sub
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
Res.Text = Str(0)
End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click


Res.Text = Str(8)
End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click


Res.Text = Str(2)
End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click


Res.Text = Str(3)
End Sub

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click


Res.Text = Str(4)
End Sub

Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click


Res.Text = Str(5)
End Sub
Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
Res.Text = Str(6)
End Sub
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
Res.Text = Str(7)
End Sub
Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
Res.Text = Str(8)
End Sub
Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click 10
Res.Text = Str(9)
Private Sub btnplu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnplu.Click
Nbre1 = Val(Res.Text)
Res.Clear()
TypeOpération = 3
End Sub

Private Sub btnneg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnneg.Click


Nbre1 = Val(Res.Text)
Res.Clear()
TypeOpération = 4
End Sub

Private Sub btnDiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDiv.Click


Nbre1 = Val(Res.Text)
Res.Clear()
TypeOpération = 1
End Sub

Private Sub btnmul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmul.Click


Nbre1 = Val(Res.Text)
Res.Clear()
TypeOpération = 2
End Sub

11
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
'Chiffre 0
Res.Text = Res.Text & Str(0)
End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click


'Chiffre 1
Res.Text = Res.Text & Str(1)
End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click


'Chiffre 2
Res.Text = Res.Text & Str(2)
End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click


'Chiffre 3
Res.Text = Res.Text & Str(3)
End Sub

12
TP 2: Réaliser une application qui affiche dans la zone du texte les numéros de 1 à 10 :

13
TP 3: Réaliser une application qui calcul le prix total de la voiture :

14
15
ListBox

Le contrôle ListBox affiche une liste d'éléments (d'objets) dans laquelle l'utilisateur peut
faire un ou plusieurs choix.

La liste contient "tarte", "poisson", "viande", "légumes", "sauces".


Ici l'élément "poisson" est sélectionné, il est en bleu.

La listBox contient une collection d'"Item":


Elle est vide au départ.
Si j'ajoute un élément à la ListBox, cela ajoute un élément à la collection Items

Vider la ListBox: Comment enlever des éléments?


ListBox1.Items.Clear() ' Enlever l'élément d'index 5:
ListBox1.Items.RemoveAt(5)
Ajouter l'élément "poisson"
ListBox1.Items.Add("poisson") ' Enlever l'élément sélectionné:
ListBox1.Items.Remove(ListBox1.SelectedItem)

' Enlever l'élément "Tokyo":


ListBox1.Items.Remove("Tokyo")

Comment lire l'élément 3?


T=ListBox1.Items(3).ToString

Comment rechercher l'élément qui contient une chaîne de caractères?


List1.FindString("pa") retourne le numéro du premier élément commençant
par 'pa'.
16
TP 4: Réaliser une application qui affiche dans la liste les noms des fruits ou les noms
des légumes selon le choix puis affiche le nom d’élément sélectionné :

17
18
19
20
21
22
23
TP6 :Réaliser une application qui affiche la plus grande des deux nombres
saisies par l’utilisateur

24
25
TP7

Le représentant d’une société de distribution des produits d’affichage électroniques sont


rémunérés de façon suivante :

¾ un fixe mensuel de 4000 DH


¾ une commission a pourcentage variable sur chaque tranche du chiffre d’affaire mensuel
:
™ une commission de 5% pour un chiffre d’affaire compris entre 0 et 1000.
™ une commission de 10% pour un chiffre d’affaire compris entre 1000 et 3000.
™ une commission de 14% pour un chiffre d’affaire supérieur à 3000.

Réaliser une application qui permet de calculer et afficher le montant total de la


rémunération de chaque représentant.

26
27
TP8 :Réaliser une application qui déclare et remplisse un tableau de 5 valeurs
numériques puis affiche ces nombres et la somme et la moyenne de ces valeurs.

28
29
30
31
32
33
34
35
36
37
38
Module Module1

Public sta(20, 6) As String


Public nb As Integer = 0

Function recherche_stagiaire(ByVal num_ins As Integer) As Integer


Dim i
For i = 0 To nb - 1
If sta(i, 0) Like num_ins Then
Return i
Exit Function
End If
Next
Return -1
End Function

End Module

39
40
Private Sub Annuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Me.Hide()
End Sub

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

If Val(note.Text) < 0 Or Val(note.Text) > 20 Then


MsgBox("la Note doit être entre 0 et 20")
Else
sta(nb, 0) = N_Insc.Text
sta(nb, 1) = nom.Text
sta(nb, 2) = prenom.Text
If F.Checked = True Then sta(nb, 3) = "F"
If M.Checked = True Then sta(nb, 3) = "M"
sta(nb, 4) = Date_n.Text
sta(nb, 5) = modul.Text
sta(nb, 6) = note.Text

nb = nb + 1

End if

End Sub

41
42
Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Dim sup As Form = New supprimer
sup.Show()
End Sub

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Dim ajou As Form = New Ajout
ajou.Show()
End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


End
End Sub

Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Dim cons As Form = New Consult
cons.Show()
End Sub

Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Dim list As Form = New liste_stagiaires
list.Show()
End Sub

Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Dim list_par_mod As Form = New Liste_par_module
list_par_mod.Show()
End Sub

43
44
Private Sub Fermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fermer.Click

Me.Hide()

End Sub

Private Sub Chercher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chercher.Click

If N_Insc.Text = "" Then

MsgBox("saisir d'abord le numéro d'inscription a cherché")

Else

Dim pos As Integer = recherche_stagiaire(Integer.Parse(N_Insc.Text))

If pos = -1 Then

MsgBox("n'existe pas")

Else
nom.Text = sta(pos, 1)
prenom.Text = sta(pos, 2)
sexe.Text = sta(pos, 3)
date_n.Text = sta(pos, 4)
modul.Text = sta(pos, 5)
note.Text = sta(pos, 6)

End If

End If

End Sub
45
Private Sub Afficher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim I

For i = 0 To nb – 1

If sta(i, 5) Like modul.Text Then

List.Items.Add(sta(i, 0) & " " & sta(i, 1) & " " & sta(i, 2) & " " & sta(i, 3) & " " & sta(i, 4) & " " & sta(i, 5) & " " & sta(i, 6))

End If

Next

End Sub

46
Private Sub liste_stagiaires_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

Dim I

For i = 0 To nb – 1

List.Items.Add(sta(i, 0) & " " & sta(i, 1) & " " & sta(i, 2) & " " & sta(i, 3) & " " & sta(i, 4) & " " & sta(i, 5) & " " & sta(i, 6))

Next

End Sub

47
48
Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click

If N_Insc.Text = "" Then

MsgBox("saisir d'abord le numéro d'inscription a supprimé")

Else

Dim pos As Integer = recherche_stagiaire(Integer.Parse(N_Insc.Text))

If pos = -1 Then
MsgBox("n'existe pas")
Else
Dim valide As String = MsgBox("voulez vous vraiment supprimer ce stagiaire?", MsgBoxStyle.YesNo)
If valide = "6" Then
Dim i
For i = pos To nb - 1
sta(i, 0) = sta(i + 1, 0)
sta(i, 1) = sta(i + 1, 1)
sta(i, 2) = sta(i + 1, 2)
sta(i, 3) = sta(i + 1, 3)
sta(i, 4) = sta(i + 1, 4)
sta(i, 5) = sta(i + 1, 5)
sta(i, 6) = sta(i + 1, 6)
Next
MsgBox("Le stagiaire a été supprimé", MsgBoxStyle.Information)
End If

End If

End If
End Sub

Private Sub Annuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 49


Me.Hide()
End Sub
Tp1 : Affichage d'un message

Avant Cliquer Après Cliquer

50
Tp2 : Calcul Montant avec intérêts

Avant Cliquer Après Cliquer

51
TP3 : Équations du 1er degrés et second degrés

52
TP4 : Analyse de chaîne de caractères

53

S-ar putea să vă placă și