TS91 Posted June 3, 2009 at 01:42 PM Report #269638 Posted June 3, 2009 at 01:42 PM 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
got_r00t? Posted June 3, 2009 at 01:54 PM Report #269644 Posted June 3, 2009 at 01:54 PM 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
ribeiro55 Posted June 3, 2009 at 02:45 PM Report #269660 Posted June 3, 2009 at 02:45 PM 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"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now