Sub ListBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown If ListBox2.Items.Count > 0 Then If e.Button <> Windows.Forms.MouseButtons.Right Then Exit Sub ContextMenuStrip1.Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y) ContextMenuStrip1.Visible = True End If End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown 'MessageBox.Show(DirectCast(sender, ListBox).Items.Count.ToString) If DirectCast(sender, ListBox).Items.Count < 1 Then Exit Sub End If If e.Button <> Windows.Forms.MouseButtons.Right Then Exit Sub End If End Sub
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown 'MessageBox.Show(DirectCast(sender, ListBox).Items.Count.ToString) If DirectCast(sender, ListBox).Items.Count < 1 Then Exit Sub End If If e.Button <> Windows.Forms.MouseButtons.Right Then Exit Sub End If ContextMenuStrip1.Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y) ContextMenuStrip1.Visible = True End Sub
Sub ListBox2_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown If ListBox2.Items.Count < 1 Then Exit Sub If e.Button <> Windows.Forms.MouseButtons.Right Then Exit Sub ContextMenuStrip1.Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y) ContextMenuStrip1.Visible = True End Sub
' ' courses form1 Option Explicit On Imports System.IO Imports System.Text Imports System.Windows.Forms Public Class Form1 Dim lindice As Integer Public produitPlusNombre As String Private Structure DDS Public ListBox As ListBox Public Item As String Public Index As Integer Public Provenance As Byte End Structure Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load AddHandler ListBox1.MouseDown, AddressOf ListBox_MouseDown AddHandler ListBox2.MouseDown, AddressOf ListBox_MouseDown AddHandler ListBox1.DragOver, AddressOf ListBox_DragOver AddHandler ListBox2.DragOver, AddressOf ListBox_DragOver AddHandler ListBox1.DragDrop, AddressOf ListBox_DragDrop AddHandler ListBox2.DragDrop, AddressOf ListBox_DragDrop ListBox1.Items.Clear() ' 32 maxi ListBox2.Items.Clear() ListBox1.AllowDrop = True ListBox2.AllowDrop = True Me.Left = 10 Me.Top = 10 Call litProduits() Call litCourses() End Sub Sub ListBox1_GiveFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles ListBox1.GiveFeedback e.UseDefaultCursors = False Cursor.Current = Cursors.PanEast End Sub Sub ListBox2_GiveFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles ListBox2.GiveFeedback e.UseDefaultCursors = False Cursor.Current = Cursors.PanWest End Sub Sub ListBox_MouseDown(ByVal sender As ListBox, ByVal e As MouseEventArgs) If sender.Items.Count > 0 Then Dim data As DDS data.Index = sender.IndexFromPoint(e.X, e.Y) If data.Index >= 0 Then sender.SelectedIndex = data.Index data.ListBox = sender If sender.Text.Trim.Length < 33 Then data.Provenance = 1 Else data.Provenance = 2 End If data.Item = sender.SelectedItem.ToString() ' contenu de la liste(i) Try sender.DoDragDrop(data, DragDropEffects.Move) Catch Ex As Exception MessageBox.Show(Ex.Message) End Try End If End If End Sub Sub ListBox_DragOver(ByVal sender As ListBox, ByVal e As DragEventArgs) If e.Data.GetDataPresent(GetType(DDS)) Then Dim data As DDS = e.Data.GetData(GetType(DDS)) If data.ListBox Is sender Then e.Effect = DragDropEffects.None Exit Sub End If e.Effect = DragDropEffects.Move End If End Sub Sub ListBox_DragDrop(ByVal sender As ListBox, ByVal e As DragEventArgs) If e.Data.GetDataPresent(GetType(DDS)) Then Dim data As DDS = e.Data.GetData(GetType(DDS)) If data.Provenance = 1 Then If Form2.TesterItem(Me, data.Item) Then data.Item = produitPlusNombre ElseIf data.Provenance = 2 Then data.Item = data.Item.padright(32).Substring(0, 32).Trim End If sender.Items.Add(data.Item) data.ListBox.Items.RemoveAt(data.Index) Call afficheCompteurs() End If End If End Sub Sub afficheCompteurs() ListBox1.Refresh() ListBox2.Refresh() Label1.Text = ListBox1.Items.Count Label2.Text = ListBox2.Items.Count Label5.Text = ListBox1.Items.Count + ListBox2.Items.Count Call faitLindex() End Sub Sub litProduits() Try ListBox1.Items.Clear() ListBox1.Items.AddRange(File.ReadAllLines("produits.txt")) Catch ex As Exception MessageBox.Show("Pas de liste des produit, voire régénérescence <!>" & Environment.NewLine & _ ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Finally Call afficheCompteurs() End Try End Sub Sub litCourses() Try ListBox2.Items.Clear() ListBox2.Items.AddRange(File.ReadAllLines("courses.txt")) Catch ex As Exception MessageBox.Show("Pas de liste courses" & Environment.NewLine & _ ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Finally Call afficheCompteurs() End Try End Sub Sub ecritProduit() Using p As TextWriter = New StreamWriter("produits.txt") For Each Item As String In ListBox1.Items p.WriteLine(Item.PadRight(32).Trim()) Next Item p.Close() End Using End Sub Sub faitLindex() Dim sLetter As String If ListBox1.Items.Count > 0 Then ListBox3.Items.Clear() For Each Item As String In ListBox1.Items sLetter = Item.Substring(0, 1).ToUpper() If Not ListBox3.Items.Contains(sLetter) Then ListBox3.Items.Add(sLetter) End If Next Item End If End Sub Sub ecritCourses() Using p As TextWriter = New StreamWriter("courses.txt") For Each Item As String In ListBox2.Items p.WriteLine(Item.PadRight(36).Substring(0, 36).Trim()) Next Item p.Close() End Using End Sub Sub ImprimerLaListeDesCoursesToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ImprimerLaListeDesCoursesToolStripMenuItem.Click If ListBox2.Items.Count > 0 Then lindice = 0 If MessageBox.Show("Confirmer l'impression de la liste des courses ", "Imprimer la liste ?", _ MessageBoxButtons.YesNo, MessageBoxIcon.Question, _ MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then Dim PageSetupDialog As New PageSetupDialog() PageSetupDialog.Document = PrintDocument1 PageSetupDialog.PageSettings.Landscape = False Me.PrintDocument1.Print() End If End If End Sub Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim police As New Font("Courier New", 12, FontStyle.Regular) Dim yPos As Integer = 10 ' pixels Do While lindice < ListBox2.Items.Count e.Graphics.DrawString(ListBox2.Items(lindice), police, Brushes.Black, 10, yPos) If lindice > 0 AndAlso (lindice Mod 60) = 0 Then e.HasMorePages = True lindice = lindice + 1 Return End If yPos = yPos + police.GetHeight lindice = lindice + 1 Loop End Sub Sub SupprimerLaListeDesCoursesToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SupprimerLaListeDesCoursesToolStripMenuItem.Click If MessageBox.Show("Supprimer la liste des courses en la réintégrant dans les produits ", _ "Confirmer la suppression ?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then For Each Item As String In ListBox2.Items ListBox1.Items.Add(Item.padright(32).Substring(0, 32).Trim) Next Item ListBox2.Items.Clear() Call afficheCompteurs() End If End Sub Sub ListBox2_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles ListBox2.MouseDown If ListBox2.Items.Count > 0 AndAlso e.Button = MouseButtons.Right Then ContextMenuStrip1.Show(e.Location.X, e.Location.Y) ContextMenuStrip1.Visible = True End If End Sub Sub ListBox3_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles ListBox3.DoubleClick Dim lettre1 As String = ListBox3.Text Dim i As Integer For i = ListBox1.TopIndex To ListBox1.Items.Count - 1 If ListBox1.Items(i).ToString.StartsWith(lettre1, StringComparison.CurrentCultureIgnoreCase) Then ListBox1.TopIndex = i Exit Sub End If Next i For i = 0 To ListBox1.Items.Count - 1 If ListBox1.Items(i).ToString.StartsWith(lettre1, StringComparison.CurrentCultureIgnoreCase) Then ListBox1.TopIndex = i Exit Sub End If Next i End Sub Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles ListBox1.MouseDown If e.Button = MouseButtons.Right Then If ListBox1.Items.Count = 0 Then ToolStripMenuItem2.Visible = False ToolStripMenuItem3.Visible = False End If ContextMenuStrip2.Show(e.Location.X, e.Location.Y) ContextMenuStrip2.Visible = True End If End Sub Sub ToolStripMenuItem1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolStripMenuItem1.Click Form3.ShowDialog(Me, "créer") End Sub Sub ToolStripMenuItem2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolStripMenuItem2.Click If ListBox1.SelectedIndex < 0 Then MessageBox.Show("Sélectionnez le produit à modifier ", "Aucun item selectionné", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else Form3.ShowDialog(Me, "modifier") End If End Sub Sub ToolStripMenuItem3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolStripMenuItem3.Click If ListBox1.SelectedIndex < 0 Then MessageBox.Show("Sélectionnez le produit à supprimer", "Rien a supprimer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf MessageBox.Show("Supprimer ce produit : " & Environment.NewLine & Environment.NewLine & _ ListBox1.Text, "Confirmer la suppression", _ MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = .DialogResult.Yes Then ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) Call ecritCourses() Call afficheCompteurs() End If End Sub Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing Dim Item As String Call ecritProduit() Call ecritCourses() Using p As TextWriter = New StreamWriter("produit_stock.txt") For Each Item In ListBox1.Items p.WriteLine(Item.PadRight(32).Substring(0, 32).Trim()) Next Item For Each Item In ListBox2.Items p.WriteLine(Item.PadRight(32).Substring(0, 32).Trim()) Next Item p.Close() End Using End Sub End Class
If ListBox2.Items.Count > 0 AndAlso e.Button = MouseButtons.Right Then ContextMenuStrip1.Show(e.Location.X, e.Location.Y) ContextMenuStrip1.Visible = True End If
Error 1 'IContainer' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\Form1.Designer.vb 18 27 courses
Error 2 'Container' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\Form1.Designer.vb 25 25 courses
Error 3 'ComponentResourceManager' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\Form1.Designer.vb 26 22 courses
Error 4 'IContainer' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\Form2.Designer.vb 18 27 courses
Error 5 'ComponentResourceManager' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\Form2.Designer.vb 25 22 courses
Error 6 'IContainer' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\Form3.Designer.vb 18 27 courses
Error 7 'ComponentResourceManager' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\Form3.Designer.vb 25 22 courses
Error 8 'GeneratedCodeAttribute' is ambiguous in the namespace 'System.CodeDom.Compiler'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Resources.Designer.vb 25 6 courses
Error 9 'EditorBrowsableAttribute' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Resources.Designer.vb 38 10 courses
Error 10 'EditorBrowsableAttribute' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Resources.Designer.vb 53 10 courses
Error 11 'GeneratedCodeAttribute' is ambiguous in the namespace 'System.CodeDom.Compiler'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Settings.Designer.vb 18 6 courses
Error 12 'EditorBrowsableAttribute' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Settings.Designer.vb 19 6 courses
Error 13 'ApplicationSettingsBase' is ambiguous in the namespace 'System.Configuration'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Settings.Designer.vb 21 18 courses
Error 14 'ApplicationSettingsBase' is ambiguous in the namespace 'System.Configuration'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Settings.Designer.vb 23 62 courses
Error 15 'EditorBrowsableAttribute' is ambiguous in the namespace 'System.ComponentModel'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Settings.Designer.vb 31 68 courses
Error 16 'Save' is not a member of 'courses.My.MySettings'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Settings.Designer.vb 34 17 courses
Error 17 'HelpKeywordAttribute' is ambiguous in the namespace 'System.ComponentModel.Design'. C:\Documents and Settings\rthomas.BUDAPLAN\Mes documents\Downloads\courses\My Project\Settings.Designer.vb 66 10 courses
dim vientDe as byte = 0
'
list1_mouseDown
vientde = 1
list1_over
if vientde <> 1 exit sub
list1_drop
met dans list2
' ----------------
list2_mouseDown
vientde = 2
list2_over
if vientde <> 2 exit sub
list2_drop
met dans list1
DRAG AND DROP (glisser et poser) entre 2 listes
-----------------------------------------------
Pour chaque liste 3 évènements
MouseDown (choix)
DragOver (Source glissement)
DragDrop (Source poser)
La manipe entre liste se fait dans le DragDrop
si test Is Source est ok...
Sub List1_MouseDown(Button...
List1.Drag vbBeginDrag
Sub List1_DragOver(Source...
If (Source Is List1) Or (Source Is List2) Then
Source.DragIcon = Picture1.Picture
Sub List2_DragDrop(Source...
If Source <> List2 Then exit sub
List1.AddItem List2.List(List2.ListIndex)
List1.Refresh
List2.RemoveItem List2.ListIndex
le plus possible vb6 (que je connais) pour que ça marche
' ' courses form 2 Option Explicit On Public Class Form2 Sub Form2_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load AddHandler Button0.Click, AddressOf Button_Click AddHandler Button1.Click, AddressOf Button_Click AddHandler Button2.Click, AddressOf Button_Click AddHandler Button3.Click, AddressOf Button_Click AddHandler Button4.Click, AddressOf Button_Click AddHandler Button5.Click, AddressOf Button_Click AddHandler Button6.Click, AddressOf Button_Click AddHandler Button7.Click, AddressOf Button_Click AddHandler Button8.Click, AddressOf Button_Click AddHandler Button9.Click, AddressOf Button_Click End Sub Public Function ChangerQuantite(ByVal Form1 As Form1, ByVal Item As String, Optional ByVal DefaultValue As Integer = 1) As Integer Label1.Text = Item Label2.Text = DefaultValue.ToString() DialogResult = DialogResult.Cancel ShowDialog(Form1) '# Mettre la StartupPosition à CenterParent pour centrer le présent formulaire... Dim Valeur As Integer = DefaultValue '# Validation de la valeur saisie If DialogResult = DialogResult.OK Then If Integer.TryParse(Label2.Text, Valeur) Then If Valeur = 0 Or Valeur > 99 Then Valeur = DefaultValue End If End If End If Me.Dispose() Return Valeur End Function Sub Button11_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button11.Click Label2.Text = String.Empty ' gomme End Sub Sub Button12_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button12.Click Me.DialogResult = DialogResult.OK Me.Close() End Sub Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) If Len(Label2.Text) 0 Or Label2.Text "0" Then Label2.Text = sender.Text End If If Len(Label2.Text) < 2 Then Label2.Text = Label2.Text & sender.Text End If End Sub End Class
' ' courses form3 ajout ou modif Option Explicit On Public Class Form3 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler Button2.Click, AddressOf Button_Click AddHandler Button3.Click, AddressOf Button_Click AddHandler Button4.Click, AddressOf Button_Click AddHandler Button5.Click, AddressOf Button_Click AddHandler Button6.Click, AddressOf Button_Click End Sub Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text &= sender.Text End Sub Public Overloads Function ShowDialog(ByVal type As String) As DialogResult Select Case type Case "créer" Label1.Visible = False Label2.Text = "CREATION" Case "modifier" Label1.Visible = True Label2.Text = "MODIFICATION" End Select Return ShowDialog() End Function End Class
' ' courses form1 Option Explicit On Imports System.Windows.Forms Imports System.IO Imports System.Text Public Class Form1 Dim lindice As Integer Private Structure DDS Public ListBox As ListBox Public Item As String Public Index As Integer End Structure Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler ListBox1.MouseDown, AddressOf ListBox_MouseDown AddHandler ListBox2.MouseDown, AddressOf ListBox_MouseDown AddHandler ListBox1.DragOver, AddressOf ListBox_DragOver AddHandler ListBox2.DragOver, AddressOf ListBox_DragOver AddHandler ListBox1.DragDrop, AddressOf ListBox_DragDrop AddHandler ListBox2.DragDrop, AddressOf ListBox_DragDrop ListBox1.Items.Clear() ' 32 maxi ListBox2.Items.Clear() ListBox1.AllowDrop = True ListBox2.AllowDrop = True Me.Left = 10 Me.Top = 10 Call litProduits() Call litCourses() End Sub Sub ListBox1_GiveFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles ListBox1.GiveFeedback e.UseDefaultCursors = False Cursor.Current = Cursors.PanEast End Sub Sub ListBox2_GiveFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles ListBox2.GiveFeedback e.UseDefaultCursors = False Cursor.Current = Cursors.PanWest End Sub Sub ListBox_MouseDown(ByVal sender As ListBox, ByVal e As MouseEventArgs) If sender.Items.Count > 0 Then Dim data As DDS data.Index = sender.IndexFromPoint(e.X, e.Y) If data.Index >= 0 Then sender.SelectedIndex = data.Index data.ListBox = sender data.Item = sender.Text.Trim ' contenu de la liste(i) Try sender.DoDragDrop(data, DragDropEffects.Move) Catch MsgBox(Err.Description & vbLf & Err.Number) End Try End If End If End Sub Sub ListBox_DragOver(ByVal sender As ListBox, ByVal e As DragEventArgs) If e.Data.GetDataPresent(GetType(DDS)) Then Dim data As DDS = e.Data.GetData(GetType(DDS)) If data.ListBox Is sender Then e.Effect = DragDropEffects.None Exit Sub End If e.Effect = DragDropEffects.Move End If End Sub Sub ListBox_DragDrop(ByVal destination As ListBox, ByVal e As DragEventArgs) If e.Data.GetDataPresent(GetType(DDS)) Then Dim data As DDS = e.Data.GetData(GetType(DDS)) If destination Is ListBox2 Then data.Item = data.Item.PadRight(34) & Form2.ChangerQuantite(Me, data.Item).ToString() Else data.Item = data.Item.PadRight(32).Substring(0, 32).Trim End If destination.Items.Add(data.Item) data.ListBox.Items.RemoveAt(data.Index) Call afficheCompteurs() End If End Sub Sub afficheCompteurs() ListBox1.Refresh() ListBox2.Refresh() Label1.Text = ListBox1.Items.Count Label2.Text = ListBox2.Items.Count Label5.Text = ListBox1.Items.Count + ListBox2.Items.Count Call faitLindex() End Sub Sub litProduits() Try ListBox1.Items.Clear() ListBox1.Items.AddRange(File.ReadAllLines("produits.txt")) Catch ex As Exception MessageBox.Show("Pas de liste des produit, voire régénérescence <!>" & Environment.NewLine & _ ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Finally Call afficheCompteurs() End Try End Sub Sub litCourses() Try ListBox2.Items.Clear() ListBox2.Items.AddRange(File.ReadAllLines("courses.txt")) Catch ex As Exception MessageBox.Show("Pas de liste courses" & Environment.NewLine & _ ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Finally Call afficheCompteurs() End Try End Sub Sub ecritProduit() Using p As TextWriter = New StreamWriter("produits.txt") For Each Item As String In ListBox1.Items p.WriteLine(Item.PadRight(32).Trim()) Next Item p.Close() End Using End Sub Sub faitLindex() Dim sLetter As String If ListBox1.Items.Count > 0 Then ListBox3.Items.Clear() For Each Item As String In ListBox1.Items sLetter = Item.Substring(0, 1).ToUpper() If Not ListBox3.Items.Contains(sLetter) Then ListBox3.Items.Add(sLetter) End If Next Item End If End Sub Sub ecritCourses() Using p As TextWriter = New StreamWriter("courses.txt") For Each Item As String In ListBox2.Items p.WriteLine(Item.PadRight(36).Substring(0, 36).Trim()) Next Item p.Close() End Using End Sub Sub ImprimerLaListeDesCoursesToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ImprimerLaListeDesCoursesToolStripMenuItem.Click If ListBox2.Items.Count > 0 Then lindice = 0 If MessageBox.Show("Confirmer l'impression de la liste des courses ", "Imprimer la liste ?", _ MessageBoxButtons.YesNo, MessageBoxIcon.Question, _ MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then Dim PageSetupDialog As New PageSetupDialog() PageSetupDialog.Document = PrintDocument1 PageSetupDialog.PageSettings.Landscape = False Me.PrintDocument1.Print() End If End If End Sub Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim police As New Font("Courier New", 12, FontStyle.Regular) Dim yPos As Integer = 10 ' pixels Do While lindice < ListBox2.Items.Count e.Graphics.DrawString(ListBox2.Items(lindice), police, Brushes.Black, 10, yPos) Select Case lindice Case 60, 120, 180, 240, 300, 360, 420, 480, 540, 600, 660, 720, 780, 840, 900 ' 16 pages... e.HasMorePages = True lindice = lindice + 1 Return End Select yPos = yPos + police.GetHeight lindice = lindice + 1 Loop End Sub Sub SupprimerLaListeDesCoursesToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SupprimerLaListeDesCoursesToolStripMenuItem.Click Dim i As Integer i = MsgBox("Supprimer la liste des courses en la réintégrant dans les produits ", vbQuestion + vbYesNo + vbDefaultButton2) If i <> vbYes Then Exit Sub For i = 0 To ListBox2.Items.Count - 1 ListBox1.Items.Add(Trim(Mid(ListBox2.Items(i), 1, 32))) Next i ListBox2.Items.Clear() Call afficheCompteurs() End Sub Sub ListBox2_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles ListBox2.MouseDown If ListBox2.Items.Count < 1 Then Exit Sub If e.Button <> Windows.Forms.MouseButtons.Right Then Exit Sub ContextMenuStrip1.Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y) ContextMenuStrip1.Visible = True End Sub Sub ListBox3_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles ListBox3.DoubleClick Dim lettre1 As String = ListBox3.Text Dim i As Integer For i = ListBox1.TopIndex To ListBox1.Items.Count - 1 If ListBox1.Items(i).ToString.StartsWith(lettre1, StringComparison.CurrentCultureIgnoreCase) Then ListBox1.TopIndex = i Exit Sub End If Next i For i = 0 To ListBox1.Items.Count - 1 If ListBox1.Items(i).ToString.StartsWith(lettre1, StringComparison.CurrentCultureIgnoreCase) Then ListBox1.TopIndex = i Exit Sub End If Next i End Sub Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles ListBox1.MouseDown If e.Button <> Windows.Forms.MouseButtons.Right Then Exit Sub If ListBox1.Items.Count = 0 Then ToolStripMenuItem2.Visible = False ToolStripMenuItem3.Visible = False End If ContextMenuStrip2.Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y) ContextMenuStrip2.Visible = True End Sub Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles ToolStripMenuItem1.Click Form3.ShowDialog("créer") End Sub Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles ToolStripMenuItem2.Click If ListBox1.SelectedIndex < 0 Then MessageBox.Show("Sélectionnez le produit à modifier ", "Aucun item selectionné", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else Form3.ShowDialog("modifier") End If End Sub Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles ToolStripMenuItem3.Click If ListBox1.SelectedIndex < 0 Then MessageBox.Show("Sélectionnez le produit à supprimer", "Rien a supprimer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) ElseIf MessageBox.Show("Supprimer ce produit : " & Environment.NewLine & Environment.NewLine & _ ListBox1.Text, "Confirmer la suppression", _ MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.Yes Then ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) Call ecritCourses() Call afficheCompteurs() End If End Sub Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing Dim Item As String Call ecritProduit() Call ecritCourses() Using p As TextWriter = New StreamWriter("produit_stock.txt") For Each Item In ListBox1.Items p.WriteLine(Item.PadRight(32).Substring(0, 32).Trim()) Next Item For Each Item In ListBox2.Items p.WriteLine(Item.PadRight(32).Substring(0, 32).Trim()) Next Item p.Close() End Using End Sub End Class
Sub ListBox2_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown MsgBox("0") If ListBox2.Items.Count > 0 AndAlso e.Button = MouseButtons.Right Then ContextMenuStrip1.Show(e.Location.X, e.Location.Y) ContextMenuStrip1.Visible = True End If End Sub
If ListBox1.Items.Count < 1 Then Exit Sub ' DANS LA LISTE UN CA MARCHE !