Jump to content

Recommended Posts

Posted

Boas,

eu sei que jameti esta duvida mas enganei me no sitio, eu queria era meter aqui.

Eu preciso de fazer uma imagem mexer juntamente com o rato.

Eu ja consegui faze la mexer mas nao tava na mesma posição que o cursor.

Se alguem poder ajudar agradeço.

cumpz

Posted

Tinha aqui este código, vê se te ajuda.

Inherits System.Windows.Forms.Form
    Public Dragging As Boolean
    Public mousex, mousey As Integer
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox


Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = MouseButtons.Left Then
            Dragging = True
            mousex = -e.X
            mousey = -e.Y
            Dim clipleft As Integer = Me.PointToClient(MousePosition).X - PictureBox1.Location.X
            Dim cliptop As Integer = Me.PointToClient(MousePosition).Y - PictureBox1.Location.Y
            Dim clipwidth As Integer = Me.ClientSize.Width - (PictureBox1.Width - clipleft)
            Dim clipheight As Integer = Me.ClientSize.Height - (PictureBox1.Height - cliptop)
            Cursor.Clip = Me.RectangleToScreen(New Rectangle(clipleft, cliptop, clipwidth, clipheight))
            PictureBox1.Invalidate()
        End If
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If Dragging Then
            'move control to new position
            Dim MPosition As New Point()
            MPosition = Me.PointToClient(MousePosition)
            MPosition.Offset(mousex, mousey)
            'ensure control cannot leave container
            PictureBox1.Location = MPosition
        End If
    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        If Dragging Then
            'end the dragging
            Dragging = False
            'Me.Capture = False
            Cursor.Clip = Nothing
            PictureBox1.Invalidate()
        End If
    End Sub
Posted

Quando preciso de algo desse género, costumo usar algo que inventei:

(Adiciona uma picturebox a uma form e substituí o código)

Public Class Form1

    Dim OffsetY As Integer
    Dim OffsetX As Integer
    Const BarraTitulo As Integer = 28
    Const Rebordo As Integer = 3

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        OffsetY = e.Y + Me.Top
        OffsetX = e.X + Me.Left
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            PictureBox1.Top = (Windows.Forms.Cursor.Position.Y - OffsetY) - BarraTitulo
            PictureBox1.Left = (Windows.Forms.Cursor.Position.X - OffsetX) - Rebordo
        End If
    End Sub
End Class

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.