Public Class Form1 Private WithEvents listboxname As New ListBox Private WithEvents buttonselect As New Button Private WithEvents buttonreturn As New Button Dim listname As New List(Of String) Dim panelbutton As New Panel Private listbutton As New List(Of Button) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load initcontrols() FillListbox() End Sub Private Sub initcontrols() With listboxname .Font = New Font("arial", 12, FontStyle.Bold) .SelectionMode = SelectionMode.MultiSimple .Location = New Point(2, 2) .Width = 200 .Height = 200 .Sorted = True End With Me.Controls.Add(listboxname) With buttonselect .Font = New Font("arial", 12, FontStyle.Bold) .TextAlign = ContentAlignment.MiddleCenter .AutoSize = True .Text = "valider" .Location = New Point(listboxname.Left + (listboxname.Width - buttonselect.Width) \ 2, listboxname.Bottom + 2) .Enabled = False End With Me.Controls.Add(buttonselect) With buttonreturn .Font = New Font("arial", 12, FontStyle.Bold) .TextAlign = ContentAlignment.MiddleCenter .AutoSize = True .Text = "retour à la liste " .Enabled = True .Visible = False End With Me.Controls.Add(buttonreturn) With panelbutton .BackColor = Color.Linen .BorderStyle = BorderStyle.Fixed3D End With Me.Controls.Add(panelbutton) End Sub Private Sub FillListbox() For iter = 1 To 50 listboxname.Items.Add("speedy gonzales" & iter.ToString) Next End Sub Private Sub listboxname_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles listboxname.SelectedIndexChanged If DirectCast(sender, ListBox).SelectedItems.Count > 0 Then 'buttonselect.Visible = True buttonselect.Enabled = True Else buttonselect.Enabled = False End If End Sub Private Sub buttonselect_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles buttonselect.MouseClick listname.Clear() For Each item As String In listboxname.SelectedItems listname.Add(item) Next 'remove all selected name For iter = listboxname.SelectedItems.Count - 1 To 0 Step -1 listboxname.Items.Remove(listboxname.SelectedItems(iter)) Next DirectCast(sender, Button).Enabled = False DirectCast(sender, Button).Visible = False listboxname.Visible = False Createbuttons() End Sub Private Sub Createbuttons() listbutton.Clear() For Each name As String In listname Dim mybutton As New Button With mybutton .Font = New Font("arial", 14, FontStyle.Bold) .TextAlign = ContentAlignment.MiddleCenter .Text = name .BackColor = Color.PowderBlue .AutoSize = True AddHandler .MouseClick, AddressOf mouseclickbutton End With listbutton.Add(mybutton) panelbutton.Controls.Add(mybutton) Next PlaceButtons() End Sub Private Sub PlaceButtons() Dim positionx As Integer Dim positiony As Integer Dim space As Integer Dim iter As Integer Dim maxwith, maxheight As Integer space = 4 positionx = 6 positiony = 6 maxwith = 0 maxheight = 0 iter = 0 For Each ctrl In panelbutton.Controls If TypeOf ctrl Is Button Then If (iter Mod 5 = 0) And iter <> 0 Then positionx = 6 positiony += DirectCast(ctrl, Button).Height + space End If DirectCast(ctrl, Button).Location = New Point(positionx, positiony) positionx += DirectCast(ctrl, Button).Width + space iter += 1 If DirectCast(ctrl, Button).Width > maxwith Then maxwith = DirectCast(ctrl, Button).Width End If If DirectCast(ctrl, Button).Height > maxheight Then maxheight = DirectCast(ctrl, Button).Height End If End If Next panelbutton.Width = maxwith * 5 + 7 * space panelbutton.Height = maxheight * 10 + 12 * space panelbutton.Left = Me.Width \ 2 - Me.panelbutton.Width \ 2 panelbutton.Top = Me.Height \ 2 - Me.panelbutton.Height \ 2 buttonreturn.Location = New Point(2, 2) If listboxname.Items.Count > 0 Then buttonreturn.Visible = True End If panelbutton.Visible = True End Sub Private Sub mouseclickbutton(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) MessageBox.Show("tu as cliqué:" & DirectCast(sender, Button).Text) End Sub Private Sub buttonreturn_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles buttonreturn.MouseClick DirectCast(sender, Button).Visible = False panelbutton.Visible = False buttonselect.Visible = True listboxname.Visible = True End Sub End Class
Private listbutton As New List(Of Button) listbutton.Clear() listbutton.Add(mybutton)
panelbutton.Width = maxwith * 5 + 7 * space
panelbutton.Width = maxwith * 5 + 6 * space
panelbutton.Height = maxheight * 10 + 12 * space
panelbutton.Height = maxheight * 10 + 11 * space
Private Sub PlaceButtons() Dim positionx As Integer Dim positiony As Integer Dim space As Integer Dim iter As Integer Dim maxwith, maxheight As Integer space = 4 positionx = space positiony = space maxwith = 0 maxheight = 0 iter = 0 For Each ctrl In panelbutton.Controls If TypeOf ctrl Is Button Then If (iter Mod 5 = 0) And iter <> 0 Then positionx = space positiony += DirectCast(ctrl, Button).Height + space End If DirectCast(ctrl, Button).Location = New Point(positionx, positiony) positionx += DirectCast(ctrl, Button).Width + space iter += 1 If DirectCast(ctrl, Button).Width > maxwith Then maxwith = DirectCast(ctrl, Button).Width End If If DirectCast(ctrl, Button).Height > maxheight Then maxheight = DirectCast(ctrl, Button).Height End If End If Next panelbutton.Width = maxwith * 5 + 6 * space panelbutton.Height = maxheight * 10 + 11 * space panelbutton.Left = Me.Width \ 2 - Me.panelbutton.Width \ 2 panelbutton.Top = Me.Height \ 2 - Me.panelbutton.Height \ 2 buttonreturn.Location = New Point(2, 2) If listboxname.Items.Count > 0 Then buttonreturn.Visible = True End If panelbutton.Visible = True End Sub
Private Sub listboxname_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles listboxname.SelectedIndexChanged If DirectCast(sender, ListBox).SelectedItems.Count > 0 Then 'buttonselect.Visible = True buttonselect.Enabled = True Else buttonselect.Enabled = False End If End Sub
Private Sub listboxname_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles listboxname.SelectedIndexChanged If listboxname.SelectedItems.Count > 0 Then 'buttonselect.Visible = True buttonselect.Enabled = True Else buttonselect.Enabled = False End If End Sub
For Each ctrl In panelbutton.Controls If TypeOf ctrl Is Button Then If (iter Mod 5 = 0) And iter <> 0 Then positionx = space positiony += DirectCast(ctrl, Button).Height + space End If DirectCast(ctrl, Button).Location = New Point(positionx, positiony)
Public Class Form1 Private WithEvents listboxname As New ListBox Private WithEvents buttonselect As New Button Private WithEvents buttonreturn As New Button Dim listname As New List(Of String) Dim panelbutton As New Panel 'la taille du plus grand bouton Dim maxsizebuton As New Size ' Private listbutton As New List(Of Button) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load initcontrols() FillListbox() GetLargerButton() End Sub Private Sub initcontrols() With listboxname .Font = New Font("arial", 12, FontStyle.Bold) .SelectionMode = SelectionMode.MultiSimple .Location = New Point(2, 2) .Width = 200 .Height = 200 .Sorted = True End With Me.Controls.Add(listboxname) With buttonselect .Font = New Font("arial", 12, FontStyle.Bold) .TextAlign = ContentAlignment.MiddleCenter .AutoSize = True .Text = "valider" .Location = New Point(listboxname.Left + (listboxname.Width - buttonselect.Width) \ 2, listboxname.Bottom + 2) .Enabled = False End With Me.Controls.Add(buttonselect) With buttonreturn .Font = New Font("arial", 12, FontStyle.Bold) .TextAlign = ContentAlignment.MiddleCenter .AutoSize = True .Text = "retour à la liste " .Enabled = True .Visible = False End With Me.Controls.Add(buttonreturn) With panelbutton .BackColor = Color.Linen .BorderStyle = BorderStyle.Fixed3D End With Me.Controls.Add(panelbutton) End Sub Private Sub FillListbox() For iter = 1 To 50 listboxname.Items.Add("BUTTON" & iter.ToString) Next End Sub Private Sub GetLargerButton() 'fixe le maxsizebutton c.a.d le button le plus large et tous les boutons auront sa taille Dim modelbutton As New Button modelbutton.Font = New Font("arial", 14, FontStyle.Bold) modelbutton.AutoSize = True maxsizebuton.Width = 0 For iter = 0 To listboxname.Items.Count - 1 'on mesure le nom modelbutton.Text = listboxname.Items(iter).ToString If modelbutton.PreferredSize.Width > maxsizebuton.Width Then maxsizebuton = modelbutton.PreferredSize End If Next End Sub Private Sub listboxname_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles listboxname.SelectedIndexChanged If DirectCast(sender, ListBox).SelectedItems.Count > 0 Then 'buttonselect.Visible = True buttonselect.Enabled = True Else buttonselect.Enabled = False End If End Sub Private Sub buttonselect_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles buttonselect.MouseClick listname.Clear() For Each item As String In listboxname.SelectedItems listname.Add(item) Next 'remove all selected name For iter = listboxname.SelectedItems.Count - 1 To 0 Step -1 listboxname.Items.Remove(listboxname.SelectedItems(iter)) Next DirectCast(sender, Button).Enabled = False DirectCast(sender, Button).Visible = False listboxname.Visible = False Createbuttons() End Sub Private Sub Createbuttons() For Each name As String In listname Dim mybutton As New Button With mybutton .Font = New Font("arial", 14, FontStyle.Bold) .TextAlign = ContentAlignment.MiddleCenter .Text = name .BackColor = Color.PowderBlue .AutoSize = False .Width = Convert.ToInt32(maxsizebuton.Width) .Height = Convert.ToInt32(maxsizebuton.Height) AddHandler .MouseClick, AddressOf mouseclickbutton End With ' listbutton.Add(mybutton) panelbutton.Controls.Add(mybutton) Next PlaceButtons() End Sub Private Sub PlaceButtons() Dim positionx As Integer Dim positiony As Integer Dim space As Integer Dim iter As Integer space = 4 positionx = space positiony = space iter = 0 For Each ctrl In panelbutton.Controls If TypeOf ctrl Is Button Then If (iter Mod 5 = 0) And iter <> 0 Then positionx = space positiony += DirectCast(ctrl, Button).Height + space End If DirectCast(ctrl, Button).Location = New Point(positionx, positiony) positionx += DirectCast(ctrl, Button).Width + space iter += 1 End If Next panelbutton.Width = Convert.ToInt32(maxsizebuton.Width) * 5 + 6 * space panelbutton.Height = Convert.ToInt32(maxsizebuton.Height) * 10 + 11 * space panelbutton.Left = Me.Width \ 2 - Me.panelbutton.Width \ 2 panelbutton.Top = Me.Height \ 2 - Me.panelbutton.Height \ 2 buttonreturn.Location = New Point(2, 2) If listboxname.Items.Count > 0 Then buttonreturn.Visible = True End If panelbutton.Visible = True End Sub Private Sub mouseclickbutton(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) MessageBox.Show("tu as cliqué:" & DirectCast(sender, Button).Text) End Sub Private Sub buttonreturn_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles buttonreturn.MouseClick DirectCast(sender, Button).Visible = False panelbutton.Visible = False buttonselect.Visible = True listboxname.Visible = True End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick End Sub
Private listbouton As New List(Of Button) Dim xp, yp As Integer xp = 1 yp = 1 For iter = 0 To n Dim mybutton As New Button With mybutton .Text = 'le non de la personne .Location = New Point(xp, yp) AddHandler .'the event for touch ,AddressOf mousebuttonresultclick End With Me.Controls.Add(mybutton) listbouton.Add(mybutton) xp += mybutton.Width + 3 Next
AddHandler .MouseClick, AddressOf monmouseclick AddHandler .MouseUp, AddressOf trucblabla Private Sub monmouseclick(ByVal sender As Object, ByVal e As System.Windows.Formss.MouseEventArgs) End Sub Private Sub trucblabla(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) End Sub
.mouseupou
.mouseclick
Les gens sont enregistrées dans une BDD.
Mais le bémol est qu'ils vont être placés en dehors de la form... Je ne vois pas comment spécifier des coordonnées afin