Piltech
Messages postés6Date d'inscriptionmercredi 25 avril 2007StatutMembreDernière intervention17 mars 2009
-
13 déc. 2007 à 11:31
Piltech
Messages postés6Date d'inscriptionmercredi 25 avril 2007StatutMembreDernière intervention17 mars 2009
-
17 déc. 2007 à 10:32
Bonjour a tous, voici mon problème :
J'ai un form sur lequel je veux créer des boutons dynamiquement et faire du dragdrop entre eux .
J'ai une classe PictureBoxWithEvents que j'ai écrit dans ce but. ( création d'une image qu'on affecte au panel de mon form)
Tout s'affiche correctement mais les evenements créer ne sont pas détéctés... Avez vous une idée ?
Form.vb Public Sub New()
InitializeComponent()
Dim height As Integer = 40
Dim picture As New PictureWithEvents(Application.StartupPath & "\img\archive.gif", "BaseTest", myBases, height)
height += 75
Dim picture2 As New PictureWithEvents(Application.StartupPath & "\img\archive.gif", "BaseTest2", transfert, height)
height += 75
Dim picture3 As New PictureWithEvents(Application.StartupPath & "\img\archive.gif", "BaseTest3", myBases, height)
End Sub
PictureWithEvents.vb
Public Class PictureWithEvents
'Label en dessous de la photo
Dim lbase As New Label
Private WithEvents pict As New Windows.Forms.PictureBox
'on lui passe le chemin de l'image, le panel sur lequel le picturebox créer va être attaché et sa position horizontal sur le panel
Public Sub New(ByRef imagePath As String, ByRef labelBase As String, ByRef mybases As Panel, ByVal height As Integer)
Dim pict As New PictureBox
pict.ImageLocation() = imagePath
mybases.Controls.Add(pict)
pict.AllowDrop = True
pict.Top = height
pict.Left = 32
pict.Anchor = AnchorStyles.Bottom
pict.Anchor = AnchorStyles.Left
pict.Anchor = AnchorStyles.Right
pict.Anchor = AnchorStyles.Top
pict.Size = New Size(48, 48)
lbase.Text = labelBase
mybases.Controls.Add(lbase)
lbase.Top = height + 50
lbase.Left = 0
lbase.TextAlign = ContentAlignment.TopCenter
lbase.Width = 112
End Sub
Private Sub picture_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pict.DragDrop
End Sub
Private Sub picture_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pict.DragOver
If Not (e.Data.GetDataPresent(GetType(System.String))) Then
e.Effect = DragDropEffects.None
Else
e.Effect = DragDropEffects.Copy
End If
End Sub
End Class
J'ai bien mes 3 bases sur mon panel à la bonne hauteur . Mais les evenements ne se déclanchent pas...
Merci d'avance a ceux qui ont le savoir et qui le partage :)
Piltech
Sub picture_DragDrop(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.DragEventArgs)
'Contenu Sub
End
Sub
Private
Sub picture_DragOver(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.DragEventArgs)
'Contenu Sub
End
Sub
Je conseille aussi de mettre les picturebox dans un arraylist afin de les manier plus rapidement après add au control. Voila pour ceux qui cherche la solution
Piltech
Messages postés6Date d'inscriptionmercredi 25 avril 2007StatutMembreDernière intervention17 mars 2009 13 déc. 2007 à 12:29
Tout d'abord merci pour cette réponse rapide...
Mais 2 problèmes se posent:
1 : Je ne peux pas declarer Picture avec withEvents car variable local
2 : Je pense alors a instancier un arraylist en global pour mon form (plus en adéquation avec l'idée du dynamique quand meme ) comme ceci :
Public Class form
dim withEvents pics as new arraylist
Public Sub New()
InitializeComponent()
Dim height As Integer = 40
pics.add(New PictureWithEvents(Application.StartupPath & "\img\archive.gif", "BaseTest", myBases, height))
height += 75
pics.add(New PictureWithEvents(Application.StartupPath & "\img\archive.gif", "BaseTest2", transfert, height))
height += 75
pics.add(New PictureWithEvents(Application.StartupPath & "\img\archive.gif", "BaseTest3", myBases, height))
End Sub
end class
Toujours présents sur mon form mais egalement toujours rien du coté des events :(
Une solution en tête ?
Merci