ehjoe
Messages postés728Date d'inscriptionsamedi 4 avril 2009StatutMembreDernière intervention30 mars 2014
-
4 janv. 2012 à 11:33
ehjoe
Messages postés728Date d'inscriptionsamedi 4 avril 2009StatutMembreDernière intervention30 mars 2014
-
7 janv. 2012 à 00:54
Bonjour,
J'ai un truc pas mal que voici en code :
Sub ListBox2_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown
MsgBox(ListBox2.Items.Count)
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
Alors comme indiqué, si ma liste (2) est vide, je sors.
Ceci fonctionne très bien si je mets un msgBox préalable, il m'indique "liste2 = 0" et ça sort...
Mais... si j'enlève le msgbox, ben, le code ne tient plus comtpe du test, que la liste soit vide ou nom il m'ouvre le menu surgissant qui suite dans la séquence du code... Ah...
Bon... je me suis dit qu'il n'avait pas le temps... alors j'ai mis un doEvents, mais ça ne change rien...
Conclusion probable : il y a un conflit de code entre les dirrérentes procédures évènementailles portant sur cette liste, mais comme je n'ai pas fais le code, évidemment, je ne suis ps non plus très capable de retrouver le conflit...
Voici le code en entier, il est en construction :
Pour mémoire : il s'agit de deux listes, l'une de produits, l'autre de courses, les éléments peuvent donc par dragAndDrop passer d'un liste à l'autre, ensuite il y a des menus surgissant afin de gérer les listes (pour l'un création, modif, sup de produit), pour l'autre, la 2, là où est le problème (impression, quantité (automatique après dragAndDrop), impression, modif quantité (à venir)...
'
' courses form1
Option Explicit On
Imports System.IO
Imports System.Text
Public Class Form1
Dim lindice As Integer
Dim provenance As Byte = 0
Public valide As Boolean
Public produitPlusNombre As String
Public typeForm3 As String
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(sender As Object, e As System.Windows.Forms.GiveFeedbackEventArgs) Handles ListBox1.GiveFeedback
e.UseDefaultCursors = False
Cursor.Current = Cursors.PanEast
End Sub
Sub ListBox2_GiveFeedback(sender As Object, e As System.Windows.Forms.GiveFeedbackEventArgs) Handles ListBox2.GiveFeedback
e.UseDefaultCursors = False
Cursor.Current = Cursors.PanWest
End Sub
Sub ListBox_MouseDown(ByVal sender As ListBox, ByVal e As System.Windows.Forms.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
provenance = 2
If Len(Trim(sender.SelectedItem.ToString())) < 33 Then provenance = 1
data.Item = sender.SelectedItem.ToString() ' 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 System.Windows.Forms.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 System.Windows.Forms.DragEventArgs)
If e.Data.GetDataPresent(GetType(DDS)) Then
Dim data As DDS = e.Data.GetData(GetType(DDS))
If provenance = 1 Then
Form2.Label1.Text = data.Item
Form2.ShowDialog(Me)
If valide = False Then Exit Sub
data.Item = produitPlusNombre
End If
If provenance = 2 Then
Dim trans As String = data.Item
data.Item = Trim(Mid(trans, 1, 32))
End If
sender.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()
ListBox1.Items.Clear()
Try
Dim p As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\produits.txt"))
While p.Peek() >= 0
ListBox1.Items.Add(p.ReadLine())
End While
p.Close()
Catch ex As Exception
MsgBox("Pas de liste des produit, voire régénérescence <!> ", vbExclamation)
End Try
Call afficheCompteurs()
End Sub
Sub litCourses()
ListBox2.Items.Clear()
Try
Dim p As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\courses.txt"))
While p.Peek() >= 0
ListBox2.Items.Add(p.ReadLine())
End While
p.Close()
Catch ex As Exception
End Try
Call afficheCompteurs()
End Sub
Sub ecritProduit()
Dim p1 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\produits.txt"))
For i = 0 To ListBox1.Items.Count - 1
p1.WriteLine(Trim(Mid(ListBox1.Items(i), 1, 32)))
Next i
p1.Close()
End Sub
Sub faitLindex()
If ListBox1.Items.Count > 1 Then
Dim i As Integer
ListBox3.Items.Clear()
For i = 0 To ListBox1.Items.Count - 1
ListBox3.Items.Add(UCase(Mid(ListBox1.Items(i), 1, 1)))
Next i
For i = ListBox3.Items.Count - 1 To 1 Step -1
If ListBox3.Items(i) = ListBox3.Items(i - 1) Then ListBox3.Items.RemoveAt(i)
Next i
ListBox3.Refresh()
End If
TextBox1.Text = ""
For i = 0 To ListBox3.Items.Count - 1
TextBox1.Text = TextBox1.Text & UCase(ListBox3.Items(i))
TextBox1.Text = TextBox1.Text & LCase(ListBox3.Items(i))
Next i
End Sub
Sub ecritCourses()
Dim p1 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\courses.txt"))
For i = 0 To ListBox2.Items.Count - 1
p1.WriteLine(Trim(Mid(ListBox2.Items(i), 1, 36)))
Next i
p1.Close()
End Sub
Sub ImprimerLaListeDesCoursesToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ImprimerLaListeDesCoursesToolStripMenuItem.Click
If ListBox2.Items.Count < 1 Then Exit Sub
lindice = 0
Dim i As Integer
i = MsgBox("Conformer l'impression de la liste des courses ", vbQuestion + vbYesNo + vbDefaultButton2)
If i <> vbYes Then Exit Sub
Dim PageSetupDialog As New PageSetupDialog()
PageSetupDialog.Document = PrintDocument1
PageSetupDialog.PageSettings.Landscape = False
Me.PrintDocument1.Print()
End Sub
Sub PrintDocument1_PrintPage(sender As System.Object, 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(sender As System.Object, e As System.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(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown
MsgBox(ListBox2.Items.Count)
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(sender As Object, e As System.EventArgs) Handles ListBox3.DoubleClick
Dim lettre1 As String = ListBox3.Items(ListBox3.SelectedIndex)
Dim lettre2 As String = Chr(ListBox3.SelectedIndex + 97)
Dim i As Integer
For i = ListBox1.TopIndex To ListBox1.Items.Count - 1
If lettre1 Mid(ListBox1.Items(i), 1, 1) Or lettre1 Mid(ListBox1.Items(i), 1, 1) Then
ListBox1.TopIndex = i
Exit Sub
End If
Next i
For i = 0 To ListBox1.Items.Count - 1
If lettre1 Mid(ListBox1.Items(i), 1, 1) Or lettre1 Mid(ListBox1.Items(i), 1, 1) Then
ListBox1.TopIndex = i
Exit Sub
End If
Next i
End Sub
Sub ListBox1_MouseDown(sender As Object, e As System.Windows.Forms.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(sender As System.Object, e As System.EventArgs) Handles ToolStripMenuItem1.Click
typeForm3 = "créer"
Form3.ShowDialog(Me)
If typeForm3 = "" Then Exit Sub
End Sub
Sub ToolStripMenuItem2_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripMenuItem2.Click
If ListBox1.SelectedIndex < 0 Then
MsgBox("Sélectionnez le produit à modifier ", vbExclamation)
Exit Sub
End If
typeForm3 = "modifier"
Form3.ShowDialog(Me)
If typeForm3 = "" Then Exit Sub
End Sub
Sub ToolStripMenuItem3_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripMenuItem3.Click
Dim sup As Integer ' supprimer list1
If ListBox1.SelectedIndex < 0 Then
MsgBox("Sélectionnez le produit à supprimer ", vbExclamation)
Exit Sub
End If
sup = MsgBox("Supprimer ce produit : " & vbLf & vbLf & ListBox1.Items(ListBox1.SelectedIndex), vbQuestion + vbYesNo + vbDefaultButton2)
If sup <> vbYes Then Exit Sub
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
Call ecritCourses()
Call afficheCompteurs()
End Sub
Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim i As Integer
Call ecritProduit()
Call ecritCourses()
ListBox4.Items.Clear()
For i = 0 To ListBox1.Items.Count - 1
ListBox4.Items.Add(Trim(Mid(ListBox1.Items(i), 1, 32)))
Next i
For i = 0 To ListBox2.Items.Count - 1
ListBox4.Items.Add(Trim(Mid(ListBox2.Items(i), 1, 32)))
Next i
Dim p As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\produit_stock.txt"))
For i = 0 To ListBox4.Items.Count - 1
p.WriteLine(Trim(Mid(ListBox4.Items(i), 1, 32)))
Next i
p.Close()
End Sub
End Class
Merci, cordialement, Joe.
A voir également:
Problème de conflit de code dans des procédures de listBox ?
ehjoe
Messages postés728Date d'inscriptionsamedi 4 avril 2009StatutMembreDernière intervention30 mars 20144 6 janv. 2012 à 22:31
Bonsoir Reynald,
Je te remercie beaucoup de ce code, mais hélas ça ne fonctionne toujours pas
Sub ListBox2_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles ListBox2.MouseDown
If e.Button <> Windows.Forms.MouseButtons.Right Or ListBox2.Items.Count < 1 Then Exit Sub
ContextMenuStrip1.Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y)
End Sub
ListBox2 vide le menu surgissant arrive quand même, la procédure n'obéit absolument pas au test puis à l'exit Sub qui devrait en résulter quand la liste est vide, ce qui affiche le menu surgissant...
Je suis étonné qu'ayant le code tu n'aies pas testé ce problème récurrent, pas grave...
*
Bref, ce code je ne suis pas en mesure de le modifier rapidement, cette fonction aurait dû me prendre deux heures, or j'en suis à une semaine, et ça peut durer encore longtemps, il faut savoir s'arrêter, alors stop
C'est sans doute bien de mettre tout en c# et en RAM, mais ça a peut être aussi ses limites, limites qui semblent dépassées. En plus, comprenant mal ou pas du tout une partie de ton code, je ne vais pas y passer ma vie à le déchiffrer pour y greffer mon code, car j'en ai encore à mettre.
Le C# écrit dans du vbNet est peut être excellent pour la gestion classique, je n'en doute pas, mais là on s'écarte un peu de la gestion et a priori ce n'est pas ça?
On est à un stade où il faudrait faire un fichier log, et écrive dans le fichier partout ou passe le programme et ce qu'il a en mémoire, je fais ça pour les gros logiciels, mais là ce serait de la gourmandise.
Donc je vais recommencer, prendre les infos sur Internet, et reposer ici la question pour que ça marche (drag and drop), je t'en informerai, et si tu veux bien m'aider, ce sera avec plaisir mais selon ma syntaxe exclusivement cette fois.
J'espère que tu ne vas pas me tancer, mais bon, ne cherches pas je te prie à modifier le code, je vais recommencer de toute façon.
Alors je te dis bonne soirée et peut être à bientôt avec plaisir, très cordialement.
ehjoe
Messages postés728Date d'inscriptionsamedi 4 avril 2009StatutMembreDernière intervention30 mars 20144 6 janv. 2012 à 23:23
Cher Reynald,
Pour le voir apparaître, je le vois apparaître, c'est le contraire pour l'instant qui m'intéresse
Bon, j'ai recommencé, dès que je coince car l'exemple de Philippe Lasserre n'est pas du mieux, sauf peut être en médecine, je passe ici...
Le lien, la référence qui lie le menu surgissant et la liste, ben non que je ne l'ai pas supprimé, puisque c'est le système qui l'a écrit quand j'ai déclarés dans la propriété appropriée de la liste le menu surgissant...
Oh, point je ne mets en doute tes compétences de C# en gestion, tu es bien meilleur que moi, le seul problème est qu'en fait je devrais passer trop de temps à comprendre ce que tu écris.
Tu n'auras de purs développeurs en vbNet que si Microsoft ne le supprime pas d'ici là, et que ces gens n'ont jamais fait de vb6, mais directement attaqué le vbNet en UIT, attends, ils arrivent
De toute façon j'ai du code à rajouter, et je ne peux pas sans perdre un temps infini et inutile pour moi, greffer mon code à un code que je ne comprends pas, ou que je dois compendre plus ou moins en regardant la doc et en testant, ce n'est pas le but de l'opération...
ehjoe
Messages postés728Date d'inscriptionsamedi 4 avril 2009StatutMembreDernière intervention30 mars 20144 7 janv. 2012 à 00:54
Reynald, suite...
Tu avais raison pour enlever l'instruction qui lie le contextMenu et la listBox, mais les instruction disent le contraire (de le mettre en propriété), en fait je ne savais pas qu'on pouvait l'appeler depuis le code sans le mettre en propriété, enfin, je ne sais pas si pour autant ça aurait fonctionné, présumons que "oui"
*
Je crois que je n'aurais pas besoin du forum, je viens de faire le code, il marche au petits oignons, menus surgissants compris, voici :
' courses form1
Option Explicit On
Public Class Form1
Dim lindex1 As Integer
Dim lindex2 As Integer
Dim vientDe As Byte
'
'
Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ListBox1.AllowDrop = True
ListBox2.AllowDrop = True
Me.Left = 15
Me.Top = 15
'
' chargement de teste
ListBox1.Items.Clear()
ListBox1.Items.Add("un")
ListBox1.Items.Add("deux")
ListBox1.Items.Add("trois")
ListBox1.Items.Add("quatre")
ListBox1.Items.Add("cinq")
ListBox1.Items.Add("six")
ListBox1.Items.Add("sept")
ListBox1.Items.Add("huit")
ListBox1.Items.Add("neuf")
End Sub
'
'
Sub ListBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
vientDe = 1
If e.Button = Windows.Forms.MouseButtons.Right Then ' contextMenu1
If ListBox1.Items.Count < 1 Then Exit Sub
ContextMenuStrip1.Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y)
End If
'
If e.Button = Windows.Forms.MouseButtons.Left Then ' fragAndDrop
If ListBox1.Items.Count < 1 Or ListBox1.IndexFromPoint(e.X, e.Y) < 0 Then Exit Sub
lindex1 = ListBox1.SelectedIndex
ListBox1.DoDragDrop(ListBox1.Items(ListBox1.IndexFromPoint(e.X, e.Y)), DragDropEffects.Move)
End If
End Sub
Sub ListBox2_DragOver(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragOver
If vientDe <> 1 Then Exit Sub
e.Effect = DragDropEffects.None
If e.Data.GetDataPresent(GetType(System.String)) True Then e.Effect DragDropEffects.Move
End Sub
Sub ListBox2_DragDrop1(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles ListBox2.DragDrop
Dim item As Object = CType(e.Data.GetData(GetType(System.String)), System.Object)
ListBox2.Items.Add(item)
ListBox1.Items.RemoveAt(lindex1)
End Sub
Sub ListBox1_GiveFeedback(sender As Object, e As System.Windows.Forms.GiveFeedbackEventArgs) Handles ListBox1.GiveFeedback
e.UseDefaultCursors = False
Cursor.Current = Cursors.PanEast
End Sub
'
'
Sub ListBox2_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseDown
vientDe = 2
If e.Button = Windows.Forms.MouseButtons.Right Then ' contextMenu2
If ListBox2.Items.Count < 1 Then Exit Sub
ContextMenuStrip2.Show(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y)
End If
'
If e.Button = Windows.Forms.MouseButtons.Left Then ' fragAndDrop
If ListBox2.Items.Count < 1 Or ListBox2.IndexFromPoint(e.X, e.Y) < 0 Then Exit Sub
lindex2 = ListBox2.SelectedIndex
ListBox2.DoDragDrop(ListBox2.Items(ListBox2.IndexFromPoint(e.X, e.Y)), DragDropEffects.Move)
End If
End Sub
Sub ListBox1_DragOver(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragOver
If vientDe <> 2 Then Exit Sub
e.Effect = DragDropEffects.None
If e.Data.GetDataPresent(GetType(System.String)) True Then e.Effect DragDropEffects.Move
End Sub
Sub ListBox1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
Dim item As Object = CType(e.Data.GetData(GetType(System.String)), System.Object)
ListBox1.Items.Add(item)
ListBox2.Items.RemoveAt(lindex2)
End Sub
Sub ListBox2_GiveFeedback(sender As Object, e As System.Windows.Forms.GiveFeedbackEventArgs) Handles ListBox2.GiveFeedback
e.UseDefaultCursors = False
Cursor.Current = Cursors.PanWest
End Sub
End Class
En te remerciant encore, à bientôt, cordialement, Joe.