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 73 74 75 76 77 78 79 80 81
|
Public Class FormQuiz
Private Question As String = String.Empty 'question courante
Private reponseUser As Boolean = True 'reponse user
Private ListReponses As List(Of ItemExcentrique) 'les reponses "justes"
Private nbPoints As Integer
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
End Sub
Private Sub FormQuiz_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Question = "Quel langage informatique n'existe pas?"
lblQuestion.Text = Question
lblQuestion.ForeColor = Color.Magenta
lblQuestion.Font = New Font("times new roman", 14.0F)
ListReponses = New List(Of ItemExcentrique) From {
New ItemExcentrique("Python", False),
New ItemExcentrique("Java", False),
New ItemExcentrique("A", True),
New ItemExcentrique("Pascal", False)}
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
ListBox1.DataSource = ListReponses
End Sub
Private Sub ListBox1_DrawItem(sender As Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
e.DrawBackground() 'arriere plan du listbox
Dim item As ItemExcentrique = CType(ListBox1.Items(e.Index), ItemExcentrique)
Dim fnt As Font = e.Font
' Selectionne un brush approprie suivant valeur de e.Sate(e.State est une combinaison de bit-flag des valeurs d'un Enum)
' &
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
' item est selectionné
e.Graphics.FillRectangle(Brushes.Yellow, e.Bounds) 'arriere plan de l'item selectionné If item.Etat = reponseUser Then
If item.Etat = reponseUser Then 'reponse user coincidente
Using greenBrush As New SolidBrush(Color.Green)
' Perform the painting.
e.Graphics.DrawString(item.Id, fnt, greenBrush, e.Bounds.X, e.Bounds.Y)
lblReponse.Text = "Vrai"
nbPoints = 5
lblPoints.Text = nbPoints.ToString()
End Using
Else
'reponse user non coincidente
Using redBrush As New SolidBrush(Color.Red)
' Perform the painting.
e.Graphics.DrawString(item.Id, fnt, redBrush, e.Bounds.X, e.Bounds.Y)
lblReponse.Text = "Faux"
nbPoints = 0
lblPoints.Text = nbPoints.ToString()
End Using
End If
Else
' item est non selectionné
Using defaultBrush As New SolidBrush(e.ForeColor)
e.Graphics.DrawString(item.Id, fnt, defaultBrush, e.Bounds.X, e.Bounds.Y)
End Using
End If
' dessine le rectangle de focus
e.DrawFocusRectangle()
End Sub
End Class |
Partager