Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:18:25+00:00 2026-06-15T05:18:25+00:00

I had some code to move the control around, but when you reached the

  • 0

I had some code to move the control around, but when you reached the end of the screen you had to release your right mouse button, right click on the image again, and drag again, .. repeat..

Now I tried to rewrite the code so the control would move without the mouse being moved. This is what I have for now:

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    Dim xx As String = DirectCast(e, MouseEventArgs).Button.ToString
    If xx = "Right" Then
        Dim Px As Point = New Point(Me.Location.X + SplitContainer1.Location.X + SplitContainer1.SplitterDistance + CInt((SplitContainer1.Width - SplitContainer1.SplitterDistance) / 2), Me.Location.Y + SplitContainer1.Location.Y + CInt(SplitContainer1.Height / 2))
        Windows.Forms.Cursor.Position = Px
        PictureBox1.Left = PictureBox1.Left + (e.X - Px.X)
        PictureBox1.Top = PictureBox1.Top + (e.Y - Px.Y)
    End If
End Sub

However the image doesn’t move, it returns to it’s original position along with the mouse.

How would I make this code move the picturebox without allowing the mouse to change position?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:18:27+00:00Added an answer on June 15, 2026 at 5:18 am

    Ah I solved it quite easily:

    Dim TemporaryMousePointerLocation As Point 
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        Static UpdateMouseOnNextMove As Boolean = False ' we need to have an update delay between each mouse move, if we update the position of the mouse each mousemove then there will be no movement
        If DirectCast(e, MouseEventArgs).Button = MouseButtons.Right Then
            If UpdateMouseOnNextMove Then
                PictureBox1.Left -= (Windows.Forms.Cursor.Position.X - TemporaryMousePointerLocation.X)
                PictureBox1.Top -= (Windows.Forms.Cursor.Position.Y - TemporaryMousePointerLocation.Y)
                Windows.Forms.Cursor.Position = TemporaryMousePointerLocation 
                UpdateMouseOnNextMove = False
            Else
                UpdateMouseOnNextMove = True ' allow cursor to move a bit so we can update the position of the mouse
            End If
        Else
            TemporaryMousePointerLocation = Windows.Forms.Cursor.Position
        End If
    End Sub
    

    If there is some better code to use, let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had some problems figuring out a good title, but hopefully the code examples
I had some code that constructed an object: function gridObjConst(id, itemName, itemPrice, itemListPrice, width,
I had some code that ran commands through Runtime.getRuntime.exec(String) , and it worked on
This question has two parts. Part 1. Yesterday I had some code which would
I had some decryption code (using wincrypt.h ) that lived within my FileReader.cpp class.
I had to convert some code (which deals with building a VBO of data
I had to de-compile some code and I don't know what this syntax is?
A co-worker asked about some code like this that originally had templates in it.
I'm writing some code here, and I'm having a had time. I have a
I'm having a problem with some code I've written. I've had to anonymize it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.