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 Picturebox


Sujet :

VB.NET

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 12
    Points : 12
    Points
    12
    Par défaut Drag & Drop Picturebox
    Bonjour à tous,

    Je suis entrain de réaliser un morpion et je souhaiterai y rajouter le drag & drop, sauf qu'il m'est impossible de drag & droper la picturebox du joueur courant (picturebox10) dans une picturebox de la grille (picturebox 1 à 9).

    J'ai pourtant initialiser chaque picturebox avec l'attribut allowDrop à True

    Je ne vois pas d'où vient l'erreur !

    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
    109
    110
    111
    112
    113
    114
    115
    116
    117
    Public Class Form2
        Dim nbCp As Integer
        Dim j1, j2 As String
        Dim imgJ1, imgJ2 As Image
     
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     
            j1 = Form1.TextBox1.Text
            j2 = Form1.TextBox2.Text
     
            ' Titre du formulaire
            Me.Text = j1 + " VS " + j2
            ' affichage du premier joueur
            Me.Label1.Text = j1
     
            ' Parcours de chaque objet dans le formulaire, si c'est une picturebox on l'initialise 
            For Each pic As Object In Me.Controls
                If TypeOf pic Is PictureBox Then
                    pic.BorderStyle = BorderStyle.FixedSingle
                    pic.Tag = ""
                    pic.Image = Nothing
                    If pic.name <> "PictureBox10" Then
                        pic.allowdrop = True
                    End If
                End If
            Next
     
            If Form1.RadioButton1.Checked Then
                PictureBox10.BackgroundImage = My.Resources.peace
                imgJ1 = My.Resources.peace
                imgJ2 = My.Resources.war
            Else
                PictureBox10.BackgroundImage = My.Resources.war
                imgJ1 = My.Resources.war
                imgJ2 = My.Resources.peace
            End If
            PictureBox10.BackgroundImageLayout = ImageLayout.Zoom
            PictureBox10.Tag = j1
            Label1.Text = j1
        End Sub
     
        Private Sub testVictoire()
            If ((PictureBox1.Tag = PictureBox2.Tag) And (PictureBox2.Tag = PictureBox3.Tag)) Or ((PictureBox4.Tag = PictureBox5.Tag) And (PictureBox5.Tag = PictureBox6.Tag)) Or ((PictureBox7.Tag = PictureBox8.Tag) And (PictureBox8.Tag = PictureBox9.Tag)) Or ((PictureBox1.Tag = PictureBox5.Tag) And (PictureBox5.Tag = PictureBox9.Tag)) Or ((PictureBox1.Tag = PictureBox4.Tag) And (PictureBox4.Tag = PictureBox7.Tag)) Or ((PictureBox2.Tag = PictureBox5.Tag) And (PictureBox5.Tag = PictureBox8.Tag)) Or ((PictureBox3.Tag = PictureBox6.Tag) And (PictureBox6.Tag = PictureBox9.Tag)) Or ((PictureBox3.Tag = PictureBox5.Tag) And (PictureBox5.Tag = PictureBox7.Tag)) Then
                MsgBox("Victoire du joueur " & PictureBox10.Tag & " !")
                finpartie()
            End If
        End Sub
     
        Private Sub finpartie()
            For Each pic As Object In Me.Controls
                If TypeOf pic Is PictureBox Then
                    pic.enabled = False
                End If
            Next
        End Sub
     
        Private Sub tourJeu()
            If PictureBox10.Tag = j1 Then
                PictureBox10.Tag = j2
                PictureBox10.BackgroundImage = imgJ2
                Label1.Text = j2
            Else
                PictureBox10.Tag = j1
                PictureBox10.BackgroundImage = imgJ1
                Label1.Text = j1
            End If
        End Sub
     
        Private Sub PictureBox_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click, PictureBox5.Click, PictureBox6.Click, PictureBox7.Click, PictureBox8.Click, PictureBox9.Click
            If PictureBox10.Tag = j1 Then
                nbCp += 1
            End If
     
            Dim pic As PictureBox = CType(sender, PictureBox)
            pic.BackgroundImage = Me.PictureBox10.BackgroundImage
            pic.BackgroundImageLayout = ImageLayout.Zoom
            pic.Enabled = False
            pic.Tag = Me.PictureBox10.Tag
     
            If nbCp >= 3 Then
                testVictoire()
            End If
     
            tourJeu()
        End Sub
     
        Dim mouseleft As Boolean = False
        Private Sub PictureBox10_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox10.MouseDown
            If e.Button = Windows.Forms.MouseButtons.Left Then
                mouseleft = True
            End If
        End Sub
     
        Private Sub PictureBox10_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox10.MouseMove
            If mouseleft Then
                PictureBox10.DoDragDrop(PictureBox10.BackgroundImage, DragDropEffects.Move Or DragDropEffects.Copy)
                mouseleft = False
            End If
        End Sub
     
     
        Private Sub PictureBox_DragEnter(sender As Object, e As DragEventArgs) Handles PictureBox1.DragEnter, PictureBox2.DragEnter, PictureBox3.DragEnter, PictureBox4.DragEnter, PictureBox5.DragEnter, PictureBox6.DragEnter, PictureBox7.DragEnter, PictureBox8.DragEnter, PictureBox9.DragEnter
            If e.Data.GetDataPresent(DataFormats.Text) Then
                If e.KeyState = 8 Then
                    e.Effect = DragDropEffects.Copy
                Else
                    e.Effect = DragDropEffects.Move
                End If
            Else
                e.Effect = DragDropEffects.None
            End If
        End Sub
     
        Private Sub PictureBox1_DragDrop(sender As Object, e As DragEventArgs) Handles PictureBox1.DragDrop, PictureBox2.DragDrop, PictureBox3.DragDrop, PictureBox4.DragDrop, PictureBox5.DragDrop, PictureBox6.DragDrop, PictureBox7.DragDrop, PictureBox8.DragDrop, PictureBox9.DragDrop
            sender.backgroundimage = e.Data.GetData(DataFormats.Bitmap)
        End Sub
    End Class
    D'avance merci

  2. #2
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2014
    Messages : 12
    Points : 12
    Points
    12
    Par défaut
    UP

Discussions similaires

  1. Drag and drop sur une PictureBox
    Par abdiouldbody dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 17/06/2009, 15h55
  2. Drag and drop d'un picturebox vers un autre
    Par karasnake dans le forum Windows Forms
    Réponses: 2
    Dernier message: 17/06/2009, 13h49
  3. [C#] Drag & Drop PictureBox
    Par Ticoche dans le forum C#
    Réponses: 7
    Dernier message: 28/04/2009, 13h15
  4. [VB][drag and drop] 2 fenêtres, 2 picturebox
    Par Bomba dans le forum VB 6 et antérieur
    Réponses: 12
    Dernier message: 22/01/2006, 00h59

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