Exercice VB: choix de Pays
Rédigé par GC Team, Publié le 02 Janvier 2012, Mise à jour le Jeudi, 15 Décembre 2022 23:04
Participez au vote ☆☆☆☆☆★★★★★
Travail à Faire :
Ecrire le code qui permet de réaliser l’interface qui contient les données suivantes :
- Une liste de choix de pays (Liste déroulante, Combobox) contenant des pays .
- Les villes du pays choisi s’affichent dans une zone d’affichage (Listeboxe, Datagride, Listeview…).
- Une zone de texte permet à l’utilisateur d’ajouter une ville à un pays sélectionné
- Une Boutton ajouter qui exécute l’instruction précédente
- Une Boutton supprimer qui permet de supprimer une ville dans un pays
- Une Boutton quitter qui permet de quitter le programme
L’interface est la suivante :

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
Public Class Form1 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim dedans As Boolean For x = 0 To ListBox1.Items.Count - 1 If TextBox1.Text = ListBox1.Items.Item(x) Then dedans = True End If Next If dedans = False Then ListBox1.Items.Add(TextBox1.Text) End If End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.Text = "Maroc" Then ListBox1.Items.Clear() ListBox1.Items.Add("rabat") ListBox1.Items.Add("Marrakech") ElseIf ComboBox1.Text = "France" Then ListBox1.Items.Clear() ListBox1.Items.Add("Paris") ElseIf ComboBox1.Text = "USA" Then ListBox1.Items.Clear() ListBox1.Items.Add("Washington") End If End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged End Sub Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem) End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click Dim Label3 As New Label() Dim Image1 As Image Image1 = Image.FromFile("D:\tout dossier nazihaphotossCARTE POSTALE\1_505881_1_34") Label3.Image = Image1 End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.Items.Add("Maroc") ComboBox1.Items.Add("France") ComboBox1.Items.Add("USA") ComboBox1.Items.Add("Germany") ComboBox1.Items.Add("Egypt") ComboBox1.Items.Add("Espagne") ComboBox1.Items.Add("Brisil") ComboBox1.Items.Add("Chine") ComboBox1.Items.Add("India") ComboBox1.Items.Add("Tunisi") ComboBox1.Items.Add("Itali") ComboBox1.Items.Add("Canada") End Sub End Class |
