IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Drag - Drop des images plusieurs fois sur le model


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Avril 2019
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Avril 2019
    Messages : 21
    Points : 22
    Points
    22
    Par défaut Drag - Drop des images plusieurs fois sur le model
    Salut tout le monde
    Svp j'ai vraiment besoin d'aide pour resoudre ce probleme
    J'ai cherché beaucoup mais malheureusement j'ai pas eu un resultat satisfaisant
    Dans ma Form1 j'ai PictureBox1 qui est le model .. et ainsi des petites PictureBox2 , PictureBox3 , PictureBox4
    Je veux faire drag and drop les images ( PictureBox2,3,4 ) sur le model ( PictureBox1 ) sans deplacer les petites PictureBox2,3,4
    L'idee c'est pour ( Prévisualiser les dommages ) des vehicules .. PictureBox1 represente le model vehicul .. PictureBox 2,3 4 representes les types de dommages .. alors le type de dommage ca peut etre sur plusieurs places du vehicule .. dans ce cas par exemple PictureBox2 ou PictureBox3 PictureBox4 il faut les faire un drag-drop plusieur fois sur PictureBox1 la ou je pose ma souris sur le model .
    Nom : p_14069b5d71.jpg
Affichages : 206
Taille : 65,7 Ko
    Merci beaucoup d'avnce pour l'aide
    Amicalement
    LAIDAROS

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Si j'ai bien compris "ton objectif" tu veux utiliser le drag-drop pour "abattre" tes "images dégâts"(tes cartes) sur l'image "model.
    Sauf que le drag-drop classique remplacera ton "image model" par celle droppée,alas (hélas).
    Pour ce que tu veux faire (preview superposant un image complet des dégâts sur l'image model ,il faut dessiner sur un image "calque" chaque image "dégât" droppée ,et ensuite dessiner le "calque" sur la surface de rendu du PicModel(Graphics).

    Le drag-drop dans l'exemple code .vb qui suit n'utilise le drag-drop que pour cibler l'image "droppée" et récupérer ses coordonnées.

    NB: cerise sur le gâteau cette facon de faire n’altère pas l'image "model" d'origine.

    code behind.vb de l'exemple (1 PicModel,Pic1,Pic2,Pic3 les "degatus",un bouton permet de resetter l'mage "calque")

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
     
    Imports System.Drawing.Drawing2D
    Public Class Form1
        Private calque As Bitmap = Nothing
        Public Sub New()
     
            ' Cet appel est requis par le concepteur.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            PicModel.AllowDrop = True
     
        End Sub
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            DrawImages(PicModel, Color.Yellow)
            calque = New Bitmap(PicModel.Width, PicModel.Height)
            DrawImages(Pic1, Color.Red)
            DrawImages(Pic2, Color.Blue)
            DrawImages(Pic3, Color.Magenta)
        End Sub
        Private Sub DrawImages(pic As PictureBox, clr As Color)
            Dim imgPic As New Bitmap(pic.Width, pic.Height)
            Using grfx As Graphics = Graphics.FromImage(imgPic)
                grfx.Clear(clr)
            End Using
            pic.Image = imgPic
        End Sub
     
        Private m_MouseIsDown As Boolean
     
     
        'Handler commun pour les "petits degats" picturebox 
        Private Sub Pic3_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Pic3.MouseDown, Pic2.MouseDown, Pic1.MouseDown
            'pic sender
            Dim picSender As PictureBox = CType(sender, PictureBox)
            If Not picSender.Image Is Nothing Then
                ' Set a flag to show that the mouse is down.
                m_MouseIsDown = True
            End If
     
        End Sub
     
     
        'idem Handler commun 
        Private Sub Pic3_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Pic3.MouseMove, Pic2.MouseMove, Pic1.MouseMove
            'pic sender
            Dim picSender As PictureBox = CType(sender, PictureBox)
            If m_MouseIsDown Then
                ' Initiate dragging and allow either copy or move.
                picSender.DoDragDrop(picSender.Image, DragDropEffects.Copy)
            End If
            m_MouseIsDown = False
     
        End Sub
     
        Private Sub PicModel_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles PicModel.DragEnter
            If e.Data.GetDataPresent(DataFormats.Bitmap) Then
                e.Effect = DragDropEffects.Copy
            End If
     
        End Sub
     
     
        Private Sub PicModel_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles PicModel.DragDrop
            'ici mode habituel du drag drop
            'alas ,il a pour egget de remplacer l'image "model" par l'image "degatus catastropgus" 
            'Assign the image to the PictureBox.
            'PicModel.Image = e.Data.GetData(DataFormats.Bitmap) 
     
            Dim degatImg As Bitmap = e.Data.GetData(DataFormats.Bitmap)
            If degatImg IsNot Nothing Then
                Dim pos As Point = PicModel.PointToClient(New Point(e.X, e.Y)) 'convertit les coords relatives à l'ecran(Screen) en coords "client" du PicModel
                Using grfx As Graphics = Graphics.FromImage(calque)
                    grfx.DrawImage(degatImg, pos)
                End Using
                'Draw le calque de Preview sur la surface du PictModel(pic.image n'est pas altéré)
                PicModel.Invalidate()
            End If
     
     
        End Sub
     
        Private Sub PicModel_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PicModel.Paint
            Dim gr As Graphics = e.Graphics
            gr.DrawImage(calque, 0, 0)
     
        End Sub
     
        Private Sub btnResetCalque_Click(sender As System.Object, e As System.EventArgs) Handles btnResetCalque.Click
            If calque IsNot Nothing Then
                'reset le calque de Preview
     
                calque = New Bitmap(calque.Width, calque.Height) 'min lahaytou bakherlou
                PicModel.Invalidate()
            End If
        End Sub
    End Class
    bon code...

  3. #3
    Membre à l'essai
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Avril 2019
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Avril 2019
    Messages : 21
    Points : 22
    Points
    22
    Par défaut
    Bonjour maitre MABROUKI
    Je vous remercie 100 fois pour l'aide
    Tres gentil de votre part .. formidable et impeccable solution .. c'est exactement ce que je veux voir et avoir
    Enfin .. depuis deux mois .. grace a vous j'ai mis fin a ce cauchemar
    Avec tous mes respects .. BRAVO
    Parfaitement resolu
    Cordialement
    LAIDAROS
    N.B: Min Lahaytou Bakherlou .. ( Formidable ) wa Svp Ida s'il reste un peu chwia Bkhour .. kifech ne3mel si par exemple j'ai pose une des Pic1 ou Pic2 ou Pic3 sur PicModel par erreur .. et j'ai voulu l'effacer sans utiliser le Button car il effacera tous.

  4. #4
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    Citation Envoyé par LAIDAROS Voir le message
    kifech ne3mel si par exemple j'ai pose une des Pic1 ou Pic2 ou Pic3 sur PicModel par erreur .. et j'ai voulu l'effacer sans utiliser le Button car il effacera tous.
    Ah ,bah pour gérer cette situation épineuse il faut un outil adéquat: un Class Utilitaire est nécessaire qui mémorise le "picture abattu" ainsi que sa positions dans un List(Of Class Utilitaire)

    A chaque drop on ajoute une instance du Class Utilitaire à List(Of Class Utilitaire).
    On peint cette fois les elements de ce List(Of Class Utilitaire) à chaque invalidation du PicModel.
    Pour l'effacer on "clear" le List(Of Class Utilitaire) & on invalide PicModel.
    Pour effacer un "element' donné on clique( ou double clique si tu veux) sur le pic voulu pour le supprimer du List(Of Class Utilitaire) & on invalide PicModel

    Tu remarques que le "calque" image est remis à zéro à chaque invalidation de PicModel.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
     
    Public Class Form2
        Private calque As Bitmap = Nothing
        Private dropppedPictures As New List(Of DroppedPic)
     
        Public Sub New()
     
            ' Cet appel est requis par le concepteur.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            PicModel.AllowDrop = True
     
        End Sub
        Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            DrawImages(PicModel, Color.Yellow)
            calque = New Bitmap(PicModel.Width, PicModel.Height)
            DrawImages(Pic1, Color.Red)
            DrawImages(Pic2, Color.Blue)
            DrawImages(Pic3, Color.Magenta)
        End Sub
        Private Sub DrawImages(pic As PictureBox, clr As Color)
            Dim imgPic As New Bitmap(pic.Width, pic.Height)
            Using grfx As Graphics = Graphics.FromImage(imgPic)
                grfx.Clear(clr)
            End Using
            pic.Image = imgPic
        End Sub
        Private m_MouseIsDown As Boolean
        Private m_DroppedPic As DroppedPic = Nothing
        Private Sub Pic3_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Pic3.MouseDown, Pic2.MouseDown, Pic1.MouseDown
            'pic sender
            Dim picSender As PictureBox = CType(sender, PictureBox)
            If Not picSender.Image Is Nothing Then
                ' Set a flag to show that the mouse is down.
                m_MouseIsDown = True
                m_DroppedPic = New DroppedPic() With {.Picture = picSender}
     
            End If
        End Sub
     
        Private Sub Pic3_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Pic3.MouseMove, Pic2.MouseMove, Pic1.MouseMove
            'pic sender
            Dim picSender As PictureBox = CType(sender, PictureBox)
            If m_MouseIsDown Then
                ' Initiate dragging and allow either copy or move.
                picSender.DoDragDrop(picSender.Image, DragDropEffects.Copy)
            End If
            m_MouseIsDown = False
        End Sub
        Private Sub PicModel_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles PicModel.DragEnter
            If e.Data.GetDataPresent(DataFormats.Bitmap) Then
                e.Effect = DragDropEffects.Copy
            End If
        End Sub
     
        Private Sub PicModel_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles PicModel.DragDrop
            'ici mode habituel du drag drop
            'alas ,il a pour egget de remplacer l'image "model" par l'image "degatus catastropgus" 
            'Assign the image to the PictureBox.
            'PicModel.Image = e.Data.GetData(DataFormats.Bitmap) 
     
            Dim degatImg As Bitmap = e.Data.GetData(DataFormats.Bitmap)
            If degatImg IsNot Nothing Then
                Dim pos As Point = PicModel.PointToClient(New Point(e.X, e.Y)) 'convertit les coords relatives à l'ecran(Screen) en coords "client" du PicModel
                m_DroppedPic.AtPoint = pos
                dropppedPictures.Add(m_DroppedPic)
                'Draw le calque de Preview sur la surface du PictModel(pic.image n'est pas altéré)
                PicModel.Invalidate()
            End If
        End Sub
        Private Sub PicModel_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PicModel.Paint
            Dim gr As Graphics = e.Graphics
            'reset calque 
            calque = New Bitmap(PicModel.Width, PicModel.Height) 'EN GDI CA CREE UN BITMAP TRANSPARENT
            Using grfx As Graphics = Graphics.FromImage(calque)
                For Each item In dropppedPictures
                    grfx.DrawImage(item.Picture.Image, item.AtPoint)
                Next
            End Using
            gr.DrawImage(calque, 0, 0)
        End Sub
     
        Private Sub btnResetCalque_Click(sender As System.Object, e As System.EventArgs) Handles btnResetCalque.Click
            If calque IsNot Nothing Then calque = New Bitmap(calque.Width, calque.Height) 'min lahaytou bakherlou
            'efface la liste
            dropppedPictures.Clear()
     
            PicModel.Invalidate()
     
        End Sub
     
        Private Sub Pic3_Click(sender As System.Object, e As System.EventArgs) Handles Pic3.Click, Pic2.Click, Pic1.Click
            Dim clicked As PictureBox = CType(sender, PictureBox)
            Dim target As DroppedPic = dropppedPictures.Find(Function(x) x.Picture Is clicked)
            If target IsNot Nothing Then
                dropppedPictures.Remove(target) 'supprime le DroppedPic
                PicModel.Invalidate()
            End If
     
     
        End Sub
    End Class
    Public Class DroppedPic
        Public Property Picture As PictureBox
        Public Property AtPoint As Point
     
    End Class
    bon code...

  5. #5
    Membre à l'essai
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Avril 2019
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Avril 2019
    Messages : 21
    Points : 22
    Points
    22
    Par défaut
    Slt cher MABROUKI
    Merci beaucoup pour l'aide
    Tres gentil de votre part .. merci encore
    J'ai pris tel qu'il est .. mais malheureusement rien ne s'efface avec Click ou avec DoubleClick .. avec le Button RESET .. ca fonctionne tres tres bien .. car il effacera tous .. mais on admittant que j'ai pose 15 calques sur PicModel et si j'ai voulu effacer uniquement quelques calques .. on cliquant .. malheureusement rien ne se passe..
    Merci beaucoup d'avance pour l'aide
    Amicalement
    LAIDAROS

  6. #6
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    Citation Envoyé par LAIDAROS Voir le message
    Slt cher MABROUKI
    mais on admettant que j'ai pose 15 calques sur PicModel et si j'ai voulu effacer uniquement quelques calques .. on cliquant .. malheureusement rien ne se passe..

    LAIDAROS
    L'artillerie "russe" vient à bout de tous les obstacles.
    Cette version revue "draggue" les "pics dégâts" eux mêmes(kourrou men lahyatou) en les clonant et en assignat à chaque "clone pic degat" PicModel comme parent.
    Pour supprimer tous les "pics clones" droppés le bouton vire tous les "pic clone" de PicModel.
    Pour supprimer un "pic clone" on double clique dessus .
    code behind .vb revu plus simple en core que le précédent en espérant qu'il fera ton bonheur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     
    Public Class Form3
        Public Sub New()
     
            ' Cet appel est requis par le concepteur.
            InitializeComponent()
     
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            PicModel.AllowDrop = True
        End Sub
     
        Private Sub Form3_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            DrawImages(PicModel, Color.Yellow)
            DrawImages(Pic1, Color.Red)
            DrawImages(Pic2, Color.Blue)
            DrawImages(Pic3, Color.Magenta)
     
        End Sub
        Private Sub DrawImages(pic As PictureBox, clr As Color)
            Dim imgPic As New Bitmap(pic.Width, pic.Height)
            Using grfx As Graphics = Graphics.FromImage(imgPic)
                grfx.Clear(clr)
            End Using
            pic.Image = imgPic
        End Sub
        Private Sub Pic3_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Pic3.MouseDown, Pic2.MouseDown, Pic1.MouseDown
            'pic sender
            Dim picSender As PictureBox = CType(sender, PictureBox)
            picSender.DoDragDrop(picSender, DragDropEffects.Copy)
        End Sub
     
     
        Private Sub PicModel_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles PicModel.DragEnter
                e.Effect = DragDropEffects.Copy
     
        End Sub
     
        Private Sub PicModel_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles PicModel.DragDrop
            Dim picToDrop As PictureBox = CType(e.Data.GetData(GetType(PictureBox)), PictureBox)
     
            Dim pos As New Point(e.X, e.Y)
            Dim picClone As New PictureBox
            picClone.Location = PicModel.PointToClient(pos)
            picClone.Image = picToDrop.Image
            picClone.Size = picToDrop.Size
            picClone.Parent = CType(sender, PictureBox)
            'handler du pic clone
            AddHandler picClone.MouseDoubleClick, AddressOf degatclicked
        End Sub
     
     
        Private Sub btnClearPicModel_Click(sender As System.Object, e As System.EventArgs) Handles btnClearPicModel.Click
            Dim tempList As New List(Of PictureBox)
            For Each item In PicModel.Controls
                If TypeOf (item) Is PictureBox Then
                    tempList.Add(item)
                End If
     
            Next
            For Each item In tempList
                PicModel.Controls.Remove(item)
     
            Next
     
     
        End Sub
     
        Private Sub degatclicked(sender As Object, e As MouseEventArgs)
            Dim picTarget As PictureBox = CType(sender, PictureBox)
            If PicModel.Controls.Contains(picTarget) Then
                'remove le handler du target
                RemoveHandler picTarget.MouseDoubleClick, AddressOf degatclicked
                PicModel.Controls.Remove(picTarget)
            End If
        End Sub
     
    End Class
    bon code...

  7. #7
    Membre à l'essai
    Homme Profil pro
    Auditeur informatique
    Inscrit en
    Avril 2019
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Auditeur informatique

    Informations forums :
    Inscription : Avril 2019
    Messages : 21
    Points : 22
    Points
    22
    Par défaut
    BRAVO ..
    Maintenant ca fonctionne tres tres bien .. comme j'ai voulu
    Merci cher MABROUKI .. tres tres gentil de votre part .. merci pour tous ( Kath'ar elf kheyrek )
    Amicalement
    LAIDAROS

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Recopier des images plusieurs fois
    Par wyzer dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 06/10/2010, 11h57
  2. bouton entree plusieurs fois sur un form
    Par lili2704 dans le forum Struts 1
    Réponses: 5
    Dernier message: 29/06/2007, 14h19
  3. Réponses: 2
    Dernier message: 14/06/2006, 08h53
  4. Réponses: 3
    Dernier message: 14/04/2006, 09h32
  5. (EXCEL) Effacer des images gif insérées sur une feuille ?
    Par romo3 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 27/08/2005, 21h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo