none
je veut que le bouton de la réponse juste prend l'emplacement d'un label à emplacement juste RRS feed

  • Question

  • je veut que si je déplace le bouton de la réponse juste dans l'emplacement de la label juste q'ile pred la place

    de plus si je déplace le bouton de la réponse faute vers la label juste ce bouton revient à son emplacement

    merci de maider ...........Code:

    Public

     

    Class Form1

     

    Dim x As Integer

     

    Dim y As Integer 

     

    Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown

     

    If e.Button = Windows.Forms.MouseButtons.Left Then

    x = e.X

    y = e.Y

     

    End If

     

    End Sub

     

     

    Private Sub Button11_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove

     

    If e.Button = Windows.Forms.MouseButtons.Left Then

    Button1.Left += (e.X - x)

    Button1.Top += (e.Y - y)

     

    End If

     

    End Sub

     

     

     

     

    Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown

     

    If e.Button = Windows.Forms.MouseButtons.Left Then

    x = e.X

    y = e.Y

     

    End If

     

    End Sub

     

     

    Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove

     

    If e.Button = Windows.Forms.MouseButtons.Left Then

    Button2.Left += (e.X - x)

    Button2.Top += (e.Y - y)

     

    End If

     

    End Sub

     

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

     

    End Sub

    End

     

    Class

    dimanche 31 octobre 2010 10:41

Réponses

  • Bonjour,

    Je vous propose celà :

    Public Class Form1
    
      Dim label1 As New Label
      Dim label2 As New Label
      Dim Button1 As New Button
      Dim positionClick As Point
      Dim positionLabel As Point
    
      Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        Button1.Top = (Me.Height - Button1.Height) / 3
        Button1.Left = 32
        Button1.Text = ""
        Button1.Enabled = False
        label1.AutoSize = True
        label1.Text = "A. Show Me"
        label1.Tag = "oui"
        label1.Left = Button1.Left + Button1.Width + 48
        label1.Top = Button1.Top - Button1.Height
        label2.AutoSize = True
        label2.Text = "B. Bad Answer"
        label2.Tag = "non"
        label2.Left = label1.Left
        label2.Top = Button1.Top + Button1.Height * 2
        label1.Cursor = Cursors.SizeAll
        label2.Cursor = Cursors.SizeAll
        Me.Controls.AddRange(New Control() {label1, label2, Button1})
        AddHandler label1.MouseDown, AddressOf Label_MouseDown
        AddHandler label1.MouseMove, AddressOf Label_MouseMove
        AddHandler label1.MouseUp, AddressOf Label_MouseUp
        AddHandler label2.MouseDown, AddressOf Label_MouseDown
        AddHandler label2.MouseMove, AddressOf Label_MouseMove
        AddHandler label2.MouseUp, AddressOf Label_MouseUp
        AddHandler Button1.Click, AddressOf Button1_Click
    
      End Sub
    
      Private Sub Label_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Left Then
          positionLabel = sender.location
          positionClick = e.Location
        End If
      End Sub
    
      Private Sub Label_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Left Then
          sender.location = New Point(sender.Location.X + e.X - positionClick.X, sender.Location.Y + e.Y - positionClick.Y)
        End If
      End Sub
    
      Private Sub Label_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Left And _
        sender.location.X >= Button1.Left And sender.location.X <= Button1.Left + Button1.Width And _
        sender.location.Y >= Button1.Top And sender.location.Y <= Button1.Top + Button1.Height Or _
        sender.location.x + sender.width >= Button1.Left And sender.location.y + sender.height >= Button1.Top Then
          If sender.tag = "oui" Then
            Button1.Text = "Show Me"
            Button1.Enabled = True
            sender.visible = False
          End If
        End If
        sender.location = positionLabel
      End Sub
    
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox("Good Answer")
      End Sub
    End Class
    
    

    • Marqué comme réponse Alex Petrescu lundi 8 novembre 2010 09:58
    mercredi 3 novembre 2010 16:18

Toutes les réponses

  • Bonjour,

    Voici, testé, n'oublies pas de cliquer en haut à gauche sur ma réponse dans le rectangle où est le triangle vert, merci :o)

    Option Explicit On
    Public Class Form1
     Dim okBouge As Boolean
     Dim positionClick As Point
     Dim posit2(2) As Long
    
     Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim v As Double = 120
      Label1.Width = v
      Label1.Height = v / 2
      Label1.Left = v * 2
      Label1.Top = v
      Label1.Text = "reponse"
      Button1.Width = v
      Button1.Height = v / 2
      Button1.Left = v / 2
      Button1.Top = v / 2
      Button1.Text = "bonne réponse"
      Button1.BackColor = Color.Yellow
      Button2.Width = v
      Button2.Height = v / 2
      Button2.Left = v / 2
      posit2(1) = v / 2
      Button2.Top = v * 1.5
      posit2(2) = v * 1.5
      Button2.Text = "mauvaise réponse"
      Button2.BackColor = Color.Yellow
      Button2.Focus()
      Me.BackColor = Color.White
      okBouge = True
     End Sub
    
     Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
      If (e.Button = MouseButtons.Left) Then positionClick = e.Location
     End Sub
    
     Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
      If (e.Button <> MouseButtons.Left) Or okBouge = False Then Exit Sub
      Dim currentControl As Control
      currentControl = CType(sender, Control)
      currentControl.Location = New Point(currentControl.Location.X + e.X - positionClick.X, currentControl.Location.Y + e.Y - positionClick.Y)
      If Button1.Left = Label1.Left And Button1.Top = Label1.Top Then
       Button1.BackColor = Color.Green
       okBouge = False
       Exit Sub
      End If
     End Sub
    
     Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
      If (e.Button = MouseButtons.Left) Then positionClick = e.Location
     End Sub
    
     Sub Button2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
      If (e.Button <> MouseButtons.Left) Then Exit Sub
      Dim currentControl As Control
      currentControl = CType(sender, Control)
      currentControl.Location = New Point(currentControl.Location.X + e.X - positionClick.X, currentControl.Location.Y + e.Y - positionClick.Y)
      Dim i As Long
      If Button2.Left = Label1.Left And Button2.Top = Label1.Top Then
       Button2.BackColor = Color.Red
       My.Application.DoEvents()
       System.Threading.Thread.Sleep(1500)
       Button2.Left = posit2(1)
       Button2.Top = posit2(2)
       Button2.BackColor = Color.Yellow
       Exit Sub
      End If
     End Sub
    End Class
    

    Cordialement.


    Joseph Attila PUSZTAY
    EhJoe       Logiciels       Romans       Ecrire
    • Proposé comme réponse EhJoe dimanche 31 octobre 2010 14:20
    dimanche 31 octobre 2010 14:20
  • Bonjour,

     

    Je vous propose ces deux méthodes :

    Private Sub Button1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp

            If Button1.Left > Label1.Left _

               And Button1.Left < Label1.Left + Label1.Width _

               And Button1.Top > Label1.Top _

               And Button1.Top < Label1.Top + Label1.Height Then

                Button1.Top = Label1.Top

                Button1.Left = Label1.Left

            End If

        End Sub

     

        Private Sub Button2_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp

            If Button2.Left > Label1.Left _

             And Button2.Left < Label1.Left + Label1.Width _

             And Button2.Top > Label1.Top _

             And Button2.Top < Label1.Top + Label1.Height Then

                Button2.Top = 180

                Button2.Left = 60

            End If

        End Sub

     

     

    Si le coin du bouton se trouve à l’intérieur du rectangle du Label, on change les coordonnées du bouton :

    1.   Prendre les coordonnées du Label si « bonne réponse »

    2.   Retour aux coordonnées intailles si « mauvaise réponse »

     

    Cordialement,

    Alex

    ________________

    Publiez un article sur MSDN !

    Windows Phone 7

    Astuces pour Visual Studio 2010

    XNA – Développement jeux vidéo

    Didacticiels et astuces : VB.NET, C#, ASP.NET, .NET Framework, Silverlight, Workflow Foundation, WPF

    Microsoft propose ce service gratuitement, dans le but d'aider les utilisateurs et d'élargir les connaissances générales liées aux produits et technologies Microsoft. Ce contenu est fourni "tel quel" et il n'implique aucune responsabilité de la part de Microsoft.

     

     


    Suivez MSDN sur Twitter 

    mardi 2 novembre 2010 10:27
  • Bonjour,

     

    Chaker001, pouvez-vous nous confirmer si ces réponses vous ont été utiles et si vous avez besoin d’assistance supplémentaire?

     

    Cordialement,

    Alex

    ________________

    Publiez un article sur MSDN !

    Windows Phone 7

    Astuces pour Visual Studio 2010

    XNA – Développement jeux vidéo

    Didacticiels et astuces : VB.NET, C#, ASP.NET, .NET Framework, Silverlight, Workflow Foundation, WPF

    Microsoft propose ce service gratuitement, dans le but d'aider les utilisateurs et d'élargir les connaissances générales liées aux produits et technologies Microsoft. Ce contenu est fourni "tel quel" et il n'implique aucune responsabilité de la part de Microsoft.

     

     

     


    Suivez MSDN sur Twitter 

    mercredi 3 novembre 2010 13:41
  • Bonjour,

    Je vous propose celà :

    Public Class Form1
    
      Dim label1 As New Label
      Dim label2 As New Label
      Dim Button1 As New Button
      Dim positionClick As Point
      Dim positionLabel As Point
    
      Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        Button1.Top = (Me.Height - Button1.Height) / 3
        Button1.Left = 32
        Button1.Text = ""
        Button1.Enabled = False
        label1.AutoSize = True
        label1.Text = "A. Show Me"
        label1.Tag = "oui"
        label1.Left = Button1.Left + Button1.Width + 48
        label1.Top = Button1.Top - Button1.Height
        label2.AutoSize = True
        label2.Text = "B. Bad Answer"
        label2.Tag = "non"
        label2.Left = label1.Left
        label2.Top = Button1.Top + Button1.Height * 2
        label1.Cursor = Cursors.SizeAll
        label2.Cursor = Cursors.SizeAll
        Me.Controls.AddRange(New Control() {label1, label2, Button1})
        AddHandler label1.MouseDown, AddressOf Label_MouseDown
        AddHandler label1.MouseMove, AddressOf Label_MouseMove
        AddHandler label1.MouseUp, AddressOf Label_MouseUp
        AddHandler label2.MouseDown, AddressOf Label_MouseDown
        AddHandler label2.MouseMove, AddressOf Label_MouseMove
        AddHandler label2.MouseUp, AddressOf Label_MouseUp
        AddHandler Button1.Click, AddressOf Button1_Click
    
      End Sub
    
      Private Sub Label_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Left Then
          positionLabel = sender.location
          positionClick = e.Location
        End If
      End Sub
    
      Private Sub Label_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Left Then
          sender.location = New Point(sender.Location.X + e.X - positionClick.X, sender.Location.Y + e.Y - positionClick.Y)
        End If
      End Sub
    
      Private Sub Label_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If e.Button = Windows.Forms.MouseButtons.Left And _
        sender.location.X >= Button1.Left And sender.location.X <= Button1.Left + Button1.Width And _
        sender.location.Y >= Button1.Top And sender.location.Y <= Button1.Top + Button1.Height Or _
        sender.location.x + sender.width >= Button1.Left And sender.location.y + sender.height >= Button1.Top Then
          If sender.tag = "oui" Then
            Button1.Text = "Show Me"
            Button1.Enabled = True
            sender.visible = False
          End If
        End If
        sender.location = positionLabel
      End Sub
    
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox("Good Answer")
      End Sub
    End Class
    
    

    • Marqué comme réponse Alex Petrescu lundi 8 novembre 2010 09:58
    mercredi 3 novembre 2010 16:18
  • merci c'est beaucoup moin compliqué mais le l'exécution n'accepte pas l'expression "and"
    vendredi 5 novembre 2010 19:24
  • Merci et mille merci......
    vendredi 5 novembre 2010 19:31