dim chiffre as integer = new random().next(0,7)
dim voyelle as string = new random().next(A,.......)
un Integer supérieur ou égal à 0 et inférieur à 7
dim chiffre as integer = new random().next(0,101)pour avoir un chiffre aléatoire entre 0 et 100,
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load InitGroupBox() End Sub Private Sub InitGroupBox() For Each ctrl As Control In GroupBoxConsonne.Controls If TypeOf ctrl Is TextBox Then DirectCast(ctrl, TextBox).Text = String.Empty End If Next For Each ctrl As Control In GroupBoxVoyelle.Controls If TypeOf ctrl Is TextBox Then DirectCast(ctrl, TextBox).Text = String.Empty End If Next End Sub Private Sub Buttonconsonne_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonconsonne.MouseClick Dim randomlettre As New Random Dim consonne As String = "bcdfghjklmnpqrstvwxz" Dim lettre As Char Dim x As Integer x = randomlettre.Next(0, consonne.Length) lettre = CChar(consonne.Substring(x, 1)) For Each ctrl As Control In GroupBoxConsonne.Controls If TypeOf ctrl Is TextBox Then If DirectCast(ctrl, TextBox).Text = String.Empty Then DirectCast(ctrl, TextBox).Text = lettre Exit For End If End If Next End Sub Private Sub Buttonvoyelle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonvoyelle.MouseClick Dim randomlettre As New Random Dim voyelle As String = "aeiouy" Dim lettre As Char Dim x As Integer x = randomlettre.Next(0, voyelle.Length) lettre = CChar(voyelle.Substring(x, 1)) For Each ctrl As Control In GroupBoxVoyelle.Controls If TypeOf ctrl Is TextBox Then If DirectCast(ctrl, TextBox).Text = String.Empty Then DirectCast(ctrl, TextBox).Text = lettre Exit For End If End If Next End Sub Private Sub ButtonEffacer_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ButtonEffacer.MouseClick InitGroupBox() End Sub
controls n'est pas un membre de system.array
Je dois toutefois avoir un petit souci car a chaque GroupBoxVoyelle.Controlls et GroupBoxconsonnes.Controlls, j'ai un message d'erreur me disant
Private listconsonne As New List(Of TextBox) Private listvoyelle As New List(Of TextBox) Private Sub InitList() listconsonne.Add(TextBox1) listconsonne.Add(TextBox2) listconsonne.Add(TextBox3) listconsonne.Add(TextBox4) listconsonne.Add(TextBox5) listconsonne.Add(TextBox6) listvoyelle.Add(TextBox7) listvoyelle.Add(TextBox8) End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load InitList() InitGroupBox() End Sub Private Sub InitGroupBox() For Each ctrl As Control In GroupBoxConsonne.Controls If TypeOf ctrl Is TextBox Then DirectCast(ctrl, TextBox).Text = String.Empty End If Next For Each ctrl As Control In GroupBoxVoyelle.Controls If TypeOf ctrl Is TextBox Then DirectCast(ctrl, TextBox).Text = String.Empty End If Next End Sub rivate Sub Buttonconsonne_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonconsonne.MouseClick Dim randomlettre As New Random Dim consonne As String = "bcdfghjklmnpqrstvwxz" Dim lettre As Char Dim x As Integer x = randomlettre.Next(0, consonne.Length) lettre = CChar(consonne.Substring(x, 1)) For Each element In listconsonne If element.Text = String.Empty Then element.Text = lettre Exit For End If Next End Sub Private Sub Buttonvoyelle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonvoyelle.MouseClick Dim randomlettre As New Random Dim voyelle As String = "aeiouy" Dim lettre As Char Dim x As Integer x = randomlettre.Next(0, voyelle.Length) lettre = CChar(voyelle.Substring(x, 1)) For Each element In listvoyelle If element.Text = String.Empty Then element.Text = lettre Exit For End If Next End Sub Private Sub ButtonEffacer_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ButtonEffacer.MouseClick InitGroupBox() End Sub
pour les lettres idem
1er clic sur bouton consonne = une consonne dans une textbox1
2ieme sur bouton consonne = une consonne dans une textbox2
3ieme sur bouton consonne = une consonne dans une textbox3
4ieme sur bouton consonne = une consonne dans une textbox4
5ieme sur bouton consonne = une consonne dans une textbox5
6ieme sur bouton consonne = une consonne dans une textbox6
1er clic sur bouton voyelle = une voyelle dans une textbox7
2ieme sur bouton voyelle = une voyelle dans une textbox7
On clique sur consonne ou voyelle => le textbox1 affiche une consonne ou une voyelle selon le bouton clique
On clique sur consonne ==>le textbox2 affiche une consonne ou une voyelle selon le bouton clique ... etc ... jusqu'au textbox8
On clique sur consonne ou voyelle => le textbox1 affiche une consonne ou une voyelle selon le bouton clique
On clique sur consonne ==>le textbox2 affiche une consonne ou une voyelle selon le bouton clique ... etc ... jusqu'au textbox8
Imports System.Drawing.Drawing2D Public Class Form1 Private flagstart As Boolean Dim lettre As String Dim counter As Integer Dim flagresult As Boolean Dim thetimespan As New TimeSpan Private lastmouselocation As New Point Dim starttime As New DateTime Private listlettre As New List(Of PictureBox) Private Sub InitPanelJeu() For iter = 0 To 7 Dim thepic As New PictureBox thepic.Tag = String.Empty thepic.BackColor = Color.White thepic.Width = 80 thepic.Height = 100 thepic.BorderStyle = BorderStyle.Fixed3D PanelJeu.Controls.Add(thepic) listlettre.Add(thepic) AddHandler listlettre(iter).MouseDown, AddressOf thepicMouseDown AddHandler listlettre(iter).MouseMove, AddressOf thepicMouseMove AddHandler listlettre(iter).Paint, AddressOf thepicPaint Next ButtonEffacer.Enabled = False counter = 0 Timer1.Interval = 6000 Timer1.Stop() flagstart = False progresbar.Width = 0 progresbar.Height = 12 End Sub Private Sub DisposeLettre() Dim left As Integer left = 6 For Each item In listlettre item.Location = New Point(left, 6) left += item.Width + 3 Next PanelJeu.Height = 3 * listlettre(0).Height + 20 PanelJeu.Width = listlettre(0).Width * 8 + 12 + 7 * 3 PanelJeu.Left = Me.Width \ 2 - PanelJeu.Width \ 2 PanelJeu.Top = Me.Height \ 2 - PanelJeu.Height \ 2 Buttonconsonne.Location = New Point(PanelJeu.Right + 2, PanelJeu.Top) Buttonvoyelle.Location = New Point(PanelJeu.Right + 2, Buttonconsonne.Bottom + 2) ButtonEffacer.Location = New Point(PanelJeu.Right + 2, Buttonvoyelle.Bottom + 2) flagresult = False PanelJeu.BackColor = Color.Linen End Sub Private Sub AfficheTouteLesLettres(ByVal gr As System.Drawing.Graphics, ByVal thepic As PictureBox) Dim myfont As New Font("arial", 34, FontStyle.Bold, GraphicsUnit.Pixel) Dim mesure As New SizeF mesure = gr.MeasureString(thepic.Tag.ToString, myfont) gr.DrawString(thepic.Tag, myfont, Brushes.Black, (thepic.Width - mesure.Width) \ 2, (thepic.Height - mesure.Height) \ 2) End Sub Private Sub Buttonconsonne_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonconsonne.MouseClick Dim randomlettre As New Random Dim consonne As String = "bcdfghjklmnpqrstvwxz" Dim x As Integer flagstart = True x = randomlettre.Next(0, consonne.Length) lettre = consonne.Substring(x, 1) lettre = lettre.ToUpper listlettre(counter).Tag = lettre counter += 1 If counter = 8 Then Buttonconsonne.Enabled = False Buttonvoyelle.Enabled = False Timer1.Start() starttime = Now End If listlettre(counter - 1).Invalidate() End Sub Private Sub Buttonvoyelle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonvoyelle.MouseClick Dim randomlettre As New Random Dim voyelle As String = "aeiouy" Dim x As Integer flagstart = True x = randomlettre.Next(0, voyelle.Length) lettre = voyelle.Substring(x, 1) lettre = lettre.ToUpper listlettre(counter).Tag = lettre counter += 1 If counter = 8 Then Buttonvoyelle.Enabled = False Buttonconsonne.Enabled = False starttime = Now Timer1.Start() End If listlettre(counter - 1).Invalidate() End Sub Private Sub Drawprogresbar(ByRef gr As System.Drawing.Graphics) 'Dessine le progresbar Dim face(3) As Point Dim margin As Integer Dim space As Integer Dim sizelength As Integer Dim sizeheight As Integer Dim edge_colors(3) As Color margin = 2 space = 2 sizelength = progresbar.Width + 2 * space sizeheight = progresbar.Height + 2 * space face(0).X = margin face(0).Y = 2 * margin face(1).X = face(0).X + margin face(1).Y = face(0).Y - margin face(2).X = face(1).X + sizelength face(2).Y = face(1).Y face(3).X = face(0).X + sizelength face(3).Y = face(0).Y Dim path_brush As New PathGradientBrush(face) path_brush = New PathGradientBrush(face) path_brush.CenterColor = Color.CornflowerBlue edge_colors(0) = Color.CornflowerBlue edge_colors(1) = Color.Black edge_colors(2) = Color.CornflowerBlue edge_colors(3) = Color.Black path_brush.SurroundColors = edge_colors gr.FillPolygon(path_brush, face) face(0).X = margin face(0).Y = 2 * margin face(1).X = face(0).X + sizelength face(1).Y = face(0).Y face(2).X = face(1).X face(2).Y = face(1).Y + sizeheight face(3).X = face(0).X face(3).Y = face(2).Y path_brush.Dispose() path_brush = New PathGradientBrush(face) path_brush.CenterColor = Color.CornflowerBlue edge_colors(0) = Color.CornflowerBlue edge_colors(1) = Color.Black edge_colors(2) = Color.CornflowerBlue edge_colors(3) = Color.Black path_brush.SurroundColors = edge_colors gr.FillPolygon(path_brush, face) face(0).X = sizelength + margin face(0).Y = 2 * margin face(1).X = face(0).X + margin face(1).Y = face(0).Y - margin face(2).X = face(1).X face(2).Y = face(1).Y + sizeheight face(3).X = face(0).X face(3).Y = face(2).Y + margin path_brush = New PathGradientBrush(face) path_brush.CenterColor = Color.CornflowerBlue edge_colors(0) = Color.CornflowerBlue edge_colors(1) = Color.Black edge_colors(2) = Color.CornflowerBlue edge_colors(3) = Color.Black path_brush.SurroundColors = edge_colors gr.FillPolygon(path_brush, face) gr.DrawLine(Pens.Black, face(1).X, face(1).Y, face(2).X, face(2).Y) ' progresbar.Width = sizelength * 1 ' progresbar.Height = sizeheight progresbar.Left = PanelJeu.Left progresbar.Top = PanelJeu.Bottom + 3 progresbar.BringToFront() progresbar.Visible = True End Sub Private Sub ButtonEffacer_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ButtonEffacer.MouseClick Dim picturelettre As New PictureBox lettre = String.Empty For Each picturelettre In listlettre picturelettre.Tag = String.Empty picturelettre.Invalidate() Next counter = 0 progresbar.Width = 0 DisposeLettre() Buttonvoyelle.Enabled = True Buttonconsonne.Enabled = True ButtonEffacer.Enabled = False End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load InitPanelJeu() DisposeLettre() End Sub Private Sub thepicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) lastmouselocation = e.Location End Sub Private Sub thepicMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Dim pt As New Point If Not flagresult Then Exit Sub End If pt = e.Location If e.Button = Windows.Forms.MouseButtons.Left Then pt.X = (pt.X + DirectCast(sender, PictureBox).Left) - lastmouselocation.X pt.Y = (pt.Y + DirectCast(sender, PictureBox).Top) - lastmouselocation.Y DirectCast(sender, PictureBox).Location = pt PanelJeu.Invalidate() End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick thetimespan = Now - starttime If thetimespan.TotalSeconds >= 96 Then Timer1.Stop() MessageBox.Show("VOS RESULTAT", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ButtonEffacer.Enabled = True flagresult = True Exit Sub End If progresbar.Width += 1 Timer1.Interval = 100 End Sub Private Sub thepicPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) If DirectCast(sender, PictureBox).Tag <> String.Empty Then AfficheTouteLesLettres(e.Graphics, DirectCast(sender, PictureBox)) End If End Sub Private Sub progresbar_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles progresbar.Paint Drawprogresbar(e.Graphics) End Sub End Class
L'identificateur 'PanelJeu ' n'est pas valide.d'après Visual Studio
Erreur 1 Option Strict On interdit les conversions implicites de 'Single' en 'Long'.pour la ligne suivante :
gr.DrawString(thepic.Tag, myfont, Brushes.Black, (thepic.Width - mesure.Width) \ 2, (thepic.Height - mesure.Height) \ 2)
Imports System.Drawing.Drawing2D Public Class Form1 Private flagstart As Boolean Dim lettre As String Dim counter As Integer Dim flagresult As Boolean Dim thetimespan As New TimeSpan Private lastmouselocation As New Point Dim starttime As New DateTime Private listlettre As New List(Of PictureBox) Private Sub InitPanelJeu() For iter = 0 To 7 Dim thepic As New PictureBox thepic.Tag = String.Empty thepic.BackColor = Color.White thepic.Width = 80 thepic.Height = 100 thepic.BorderStyle = BorderStyle.Fixed3D PanelJeu.Controls.Add(thepic) listlettre.Add(thepic) AddHandler listlettre(iter).MouseDown, AddressOf thepicMouseDown AddHandler listlettre(iter).MouseMove, AddressOf thepicMouseMove AddHandler listlettre(iter).Paint, AddressOf thepicPaint Next ButtonEffacer.Enabled = False counter = 0 Timer1.Interval = 6000 Timer1.Stop() flagstart = False progresbar.Width = 0 progresbar.Height = 30 End Sub Private Sub DisposeLettre() Dim left As Integer left = 6 For Each item In listlettre item.Location = New Point(left, 6) left += item.Width + 3 Next PanelJeu.Height = 3 * listlettre(0).Height + 20 PanelJeu.Width = listlettre(0).Width * 8 + 12 + 7 * 3 PanelJeu.Left = Me.Width \ 2 - PanelJeu.Width \ 2 PanelJeu.Top = Me.Height \ 2 - PanelJeu.Height \ 2 PanelJeu.BackColor = Color.Linen Buttonconsonne.Location = New Point(PanelJeu.Right + 2, PanelJeu.Top) Buttonvoyelle.Location = New Point(PanelJeu.Right + 2, Buttonconsonne.Bottom + 2) ButtonEffacer.Location = New Point(PanelJeu.Right + 2, Buttonvoyelle.Bottom + 2) flagresult = False End Sub Private Sub AfficheTouteLesLettres(ByVal gr As System.Drawing.Graphics, ByVal thepic As PictureBox) Dim myfont As New Font("arial", 34, FontStyle.Bold, GraphicsUnit.Pixel) Dim mesure As New SizeF Dim x ,y As Single mesure = gr.MeasureString(thepic.Tag.ToString, myfont) gr.DrawString(thepic.Tag.ToString, myfont, Brushes.Black, (thepic.Width - mesure.Width) / 2, (thepic.Height - mesure.Height) / 2) End Sub Private Sub Buttonconsonne_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonconsonne.MouseClick Dim randomlettre As New Random Dim consonne As String = "bcdfghjklmnpqrstvwxz" Dim x As Integer flagstart = True x = randomlettre.Next(0, consonne.Length) lettre = consonne.Substring(x, 1) lettre = lettre.ToUpper listlettre(counter).Tag = lettre counter += 1 If counter = 8 Then Buttonconsonne.Enabled = False Buttonvoyelle.Enabled = False Timer1.Start() starttime = Now End If listlettre(counter - 1).Invalidate() End Sub Private Sub Buttonvoyelle_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonvoyelle.MouseClick Dim randomlettre As New Random Dim voyelle As String = "aeiouy" Dim x As Integer flagstart = True x = randomlettre.Next(0, voyelle.Length) lettre = voyelle.Substring(x, 1) lettre = lettre.ToUpper listlettre(counter).Tag = lettre counter += 1 If counter = 8 Then Buttonvoyelle.Enabled = False Buttonconsonne.Enabled = False starttime = Now Timer1.Start() End If listlettre(counter - 1).Invalidate() End Sub Private Sub Drawprogresbar(ByRef gr As System.Drawing.Graphics) 'Dessine le progresbar Dim face(3) As Point Dim margin As Integer Dim space As Integer Dim sizelength As Integer Dim sizeheight As Integer Dim edge_colors(3) As Color margin = 2 space = 2 sizelength = progresbar.Width + 2 * space sizeheight = progresbar.Height + 2 * space face(0).X = margin face(0).Y = 2 * margin face(1).X = face(0).X + margin face(1).Y = face(0).Y - margin face(2).X = face(1).X + sizelength face(2).Y = face(1).Y face(3).X = face(0).X + sizelength face(3).Y = face(0).Y Dim path_brush As New PathGradientBrush(face) path_brush = New PathGradientBrush(face) path_brush.CenterColor = Color.CornflowerBlue edge_colors(0) = Color.CornflowerBlue edge_colors(1) = Color.Black edge_colors(2) = Color.CornflowerBlue edge_colors(3) = Color.Black path_brush.SurroundColors = edge_colors gr.FillPolygon(path_brush, face) face(0).X = margin face(0).Y = 2 * margin face(1).X = face(0).X + sizelength face(1).Y = face(0).Y face(2).X = face(1).X face(2).Y = face(1).Y + sizeheight face(3).X = face(0).X face(3).Y = face(2).Y path_brush.Dispose() path_brush = New PathGradientBrush(face) path_brush.CenterColor = Color.CornflowerBlue edge_colors(0) = Color.CornflowerBlue edge_colors(1) = Color.Black edge_colors(2) = Color.CornflowerBlue edge_colors(3) = Color.Black path_brush.SurroundColors = edge_colors gr.FillPolygon(path_brush, face) face(0).X = sizelength + margin face(0).Y = 2 * margin face(1).X = face(0).X + margin face(1).Y = face(0).Y - margin face(2).X = face(1).X face(2).Y = face(1).Y + sizeheight face(3).X = face(0).X face(3).Y = face(2).Y + margin path_brush = New PathGradientBrush(face) path_brush.CenterColor = Color.CornflowerBlue edge_colors(0) = Color.CornflowerBlue edge_colors(1) = Color.Black edge_colors(2) = Color.CornflowerBlue edge_colors(3) = Color.Black path_brush.SurroundColors = edge_colors gr.FillPolygon(path_brush, face) gr.DrawLine(Pens.Black, face(1).X, face(1).Y, face(2).X, face(2).Y) ' progresbar.Width = sizelength * 1 ' progresbar.Height = sizeheight progresbar.Left = PanelJeu.Left progresbar.Top = PanelJeu.Bottom + 3 progresbar.BringToFront() progresbar.Visible = True End Sub Private Sub ButtonEffacer_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ButtonEffacer.MouseClick Dim picturelettre As New PictureBox lettre = String.Empty For Each picturelettre In listlettre picturelettre.Tag = String.Empty picturelettre.Invalidate() Next counter = 0 Timer1.Interval = 6000 progresbar.Width = 0 DisposeLettre() Buttonvoyelle.Enabled = True Buttonconsonne.Enabled = True ButtonEffacer.Enabled = False End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load InitPanelJeu() DisposeLettre() End Sub Private Sub thepicMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) lastmouselocation = e.Location End Sub Private Sub thepicMouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Dim pt As New Point If Not flagresult Then Exit Sub End If pt = e.Location If e.Button = Windows.Forms.MouseButtons.Left Then pt.X = (pt.X + DirectCast(sender, PictureBox).Left) - lastmouselocation.X pt.Y = (pt.Y + DirectCast(sender, PictureBox).Top) - lastmouselocation.Y DirectCast(sender, PictureBox).Location = pt PanelJeu.Invalidate() End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick thetimespan = Now - starttime If thetimespan.TotalSeconds >= 96 Then Timer1.Stop() MessageBox.Show("VOS RESULTAT", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ButtonEffacer.Enabled = True flagresult = True Exit Sub End If progresbar.Width += 1 Timer1.Interval = 100 End Sub Private Sub thepicPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) If DirectCast(sender, PictureBox).Tag.ToString <> String.Empty Then AfficheTouteLesLettres(e.Graphics, DirectCast(sender, PictureBox)) End If End Sub Private Sub progresbar_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles progresbar.Paint Drawprogresbar(e.Graphics) End Sub End Class