locked
Scrolling Panel With Mouse Location RRS feed

  • Question

  • Ok, so I've been bored and needed something to program so I opted with making a single player RPG creator, for this I decided to use a Panel for the screen and then Paint in what I want for maps (importing images using paint) but I want the maps to be bigger than the Panel and I want to have the mouse (for now so I can have some understanding of that) scroll around the map, basically have it further than half way down on the panel and it scrolls down, but I don't want any clicking or MouseWheel use needed or used, I just want it to follow where the mouse is.

    Long story short, I have a panel, I put the mouse further than halfway, the panel scrolls down or wherever the mouse is pointing.

    Wednesday, July 16, 2014 3:05 PM

Answers

  • Hi,

     Here is an example of one way you can do it. I used 1 large map image that is 2686x1414 for my example instead of several small images. If your using several images then that may be a bit more complicated. You would have to draw partial parts of 2, 3, or 4 images depending on where you are in your map. I also used a PictureBox instead of a Panel because it handles drawing the image much better than a Panel. I believe a PictureBox is DoubleBuffered which helps make it handle drawing the image without much flickering.

    Public Class Form1
        Private WithEvents Tmr As New Timer With {.Interval = 500}
        Private map As New Bitmap("C:\TestFolder\Map.jpg")
        Private L, R, T, B As Boolean
        Private pL, pT, plMin, ptMin As Integer
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            plMin = PictureBox1.ClientSize.Width - map.Width
            ptMin = PictureBox1.ClientSize.Height - map.Height
            pL = CInt(plMin / 2)
            pT = CInt(ptMin / 2)
        End Sub
    
        Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
            Tmr.Enabled = False
        End Sub
    
        Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            L = (e.X < CInt((PictureBox1.ClientSize.Width / 2) - 30))
            R = (e.X > CInt((PictureBox1.ClientSize.Width / 2) + 30))
            T = (e.Y < CInt((PictureBox1.ClientSize.Height / 2) - 30))
            B = (e.Y > CInt((PictureBox1.ClientSize.Height / 2) + 30))
            Tmr.Enabled = (L Or R Or T Or B)
            If Not Tmr.Enabled Then Tmr.Interval = 500
        End Sub
    
        Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
            If Tmr.Interval > 100 Then Tmr.Interval = 100
            PictureBox1.Refresh()
        End Sub
    
        Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
            If L Then
                If pL < 0 Then pL += 5
                If pL > 0 Then pL = 0
            End If
            If R Then
                If pL > plMin Then pL -= 5
                If pL < plMin Then pL = plMin
            End If
            If T Then
                If pT < 0 Then pT += 5
                If pT > 0 Then pT = 0
            End If
            If B Then
                If pT > ptMin Then pT -= 5
                If pT < ptMin Then pT = ptMin
            End If
            e.Graphics.DrawImage(map, pL, pT, map.Width, map.Height)
        End Sub
    End Class
    


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Wednesday, July 16, 2014 6:02 PM
    • Proposed as answer by Cor Ligthert Saturday, July 19, 2014 11:46 AM
    • Marked as answer by Mohenjo Daro Saturday, July 19, 2014 2:02 PM
    Wednesday, July 16, 2014 5:26 PM

All replies

  • What part do you need help with?

    The basic concept is to use the MouseMove even to keep track of when the mouse moves and to calculate its relative position to the size of the view port.  You then use that value to modify whatever you are using for a scroll offset.

    How you implement the actual scroll offset depends on how you are doing you drawing, but in short, you translate the map position by the offset to draw the image on screen.  So before you can worry about how to scroll your map, first you must determine how you will draw it.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, July 16, 2014 4:36 PM
  • Hi,

     Here is an example of one way you can do it. I used 1 large map image that is 2686x1414 for my example instead of several small images. If your using several images then that may be a bit more complicated. You would have to draw partial parts of 2, 3, or 4 images depending on where you are in your map. I also used a PictureBox instead of a Panel because it handles drawing the image much better than a Panel. I believe a PictureBox is DoubleBuffered which helps make it handle drawing the image without much flickering.

    Public Class Form1
        Private WithEvents Tmr As New Timer With {.Interval = 500}
        Private map As New Bitmap("C:\TestFolder\Map.jpg")
        Private L, R, T, B As Boolean
        Private pL, pT, plMin, ptMin As Integer
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            plMin = PictureBox1.ClientSize.Width - map.Width
            ptMin = PictureBox1.ClientSize.Height - map.Height
            pL = CInt(plMin / 2)
            pT = CInt(ptMin / 2)
        End Sub
    
        Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
            Tmr.Enabled = False
        End Sub
    
        Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            L = (e.X < CInt((PictureBox1.ClientSize.Width / 2) - 30))
            R = (e.X > CInt((PictureBox1.ClientSize.Width / 2) + 30))
            T = (e.Y < CInt((PictureBox1.ClientSize.Height / 2) - 30))
            B = (e.Y > CInt((PictureBox1.ClientSize.Height / 2) + 30))
            Tmr.Enabled = (L Or R Or T Or B)
            If Not Tmr.Enabled Then Tmr.Interval = 500
        End Sub
    
        Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
            If Tmr.Interval > 100 Then Tmr.Interval = 100
            PictureBox1.Refresh()
        End Sub
    
        Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
            If L Then
                If pL < 0 Then pL += 5
                If pL > 0 Then pL = 0
            End If
            If R Then
                If pL > plMin Then pL -= 5
                If pL < plMin Then pL = plMin
            End If
            If T Then
                If pT < 0 Then pT += 5
                If pT > 0 Then pT = 0
            End If
            If B Then
                If pT > ptMin Then pT -= 5
                If pT < ptMin Then pT = ptMin
            End If
            e.Graphics.DrawImage(map, pL, pT, map.Width, map.Height)
        End Sub
    End Class
    


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Wednesday, July 16, 2014 6:02 PM
    • Proposed as answer by Cor Ligthert Saturday, July 19, 2014 11:46 AM
    • Marked as answer by Mohenjo Daro Saturday, July 19, 2014 2:02 PM
    Wednesday, July 16, 2014 5:26 PM
  • Very nice Razerz!

    Wednesday, July 16, 2014 7:21 PM
  • Very nice Razerz!

     Thanks Tom.  8)

     I thought it may be a little more complicated until i got going on it. There is probably a few other ways to do it though. I figured you would post one of them before i got it going.   :)


    If you say it can`t be done then i`ll try it

    Wednesday, July 16, 2014 8:04 PM
  • Well, I wasn't expecting it to be overly complicated, just, I'm new and have never done this before. Anyways, that is what I'm wanting to do, but my maps would be made out of multiple images so a picture box won't work and I have to use a panel (which works surprizingly well).

    Also, I was wondering about the mouse scrolling but now I'm thinking that I shouldn't be stupid, I'm going to have the panel follow the "character" and as they move the screen will move, is that a simple change in the code?

    But Razerz, great job there!

    Wednesday, July 16, 2014 11:55 PM
  • Hi Mohenjo,

     Maybe i am not understanding the reason why you want to use a Panel. If you use the paint event to paint the moving image in a panel it will flicker as it is being repainted to make the image move one way or the other. That is why i use a PictureBox instead. It won`t flicker like a panel will.

     I also don`t understand what you mean by the Mouse Scrolling part. Are you trying to use the scroll controls of the panel somehow ?

     You say the Panel works well for you so, i take it you have it working somewhat with a panel. Can you post the code you have so we can understand how you are doing things ? Also, if you have any properties for the panel set in the design window such as any of the scroll properties please tell us what they are set to.

     "is that a simple change in the code?"

     You would need to check the position of the characters sprite instead of the mouse position to tell if the map needs to scroll up, down, left, or right. I guess it would all depend on how the character`s sprite is drawn and moved. Normally a game like this is run in a loop to detect (keys) and repaint the sprite in its new location. I imagine it could get a little complicated if your kind of new to programming.

     


    If you say it can`t be done then i`ll try it

    Thursday, July 17, 2014 1:14 AM
  • Well, with PictureBox, can I use multiple parts of pictures mixed together in it? So take a piece here and a piece there and put them together in it?
    Thursday, July 17, 2014 1:28 AM
  •  If you are drawing the Images in the Paint event or creating a graphics object of the picturebox and drawing them then you can. You should read the link below that was written by Reed who is very good at programming.

    How to Create Video Games in VB.Net (Windows Forms)

     

     I am going to get out of here for the night. I have to get up early for work.  8)

     PS - Pay close attention to what he says in the first paragraph about not using pictureboxes for the sprites.


    If you say it can`t be done then i`ll try it

    Thursday, July 17, 2014 1:47 AM
  • Well, with PictureBox, can I use multiple parts of pictures mixed together in it? So take a piece here and a piece there and put them together in it?

    How are you doing that in a panel? If you display the code you use to do that an answer would be immediate.

    If you display the code use the Insert Code Block function which is the square button to the right of the letters HTML in the toolbar at the top of an open post.


    La vida loca

    Thursday, July 17, 2014 1:57 AM
  • Well, I tried what I did with the Panel and having multiple images (basically I painted one image, then painted another image which is then put over the first image) and it does work with PictureBox, so I think I'll use that instead, but thanks for the help thus far.

     Private Sub picScreen_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picScreen.Paint
            Dim Image1 = Image.FromFile("C:\Documents and Settings\Administrator\Desktop\Programming\VB 2010 Projects\Game Creater\Graphics\bars.bmp")
            Dim ulCorner As New Point(0, 0)
            Dim urCorner As New Point(1120, 0)
            Dim llCorner As New Point(0, 832)
            Dim destPara As Point() = {ulCorner, urCorner, llCorner}
            Dim srcRect As New Rectangle(5, 5, 10, 10)
            Dim units As GraphicsUnit = GraphicsUnit.Pixel
            e.Graphics.DrawImage(Image1, destPara, srcRect, units)
    
        End Sub
    This is how you can easily insert a picture (or multiple) into a PictureBox without importing it
    Thursday, July 17, 2014 2:12 AM
  • Yes that's true. In different ways also. One way is to use Buffered Graphics.

    Option Strict On
    
    Public Class Form1
    
        ' BufferedGraphics Class http://msdn.microsoft.com/en-us/library/system.drawing.bufferedgraphics(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
    
        Dim Bmp As Bitmap
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            Me.DoubleBuffered = True
            Me.BackColor = Color.Red
            Bmp = New Bitmap("C:\Users\John\Desktop\Picture Files\Crossbones BMP.Bmp")
        End Sub
    
        Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
    
            Dim grafx As BufferedGraphics
            Dim context As BufferedGraphicsContext
            context = BufferedGraphicsManager.Current
    
            grafx = context.Allocate(Graphics.FromHwnd(Panel1.Handle), New Rectangle(CInt((Panel1.Width / 2) - (Bmp.Width / 2)), CInt((Panel1.Height / 2) - (Bmp.Height / 2)), Bmp.Width, Bmp.Height))
            grafx.Graphics.DrawImage(Bmp, CInt((Panel1.Width / 2) - (Bmp.Width / 2)), CInt((Panel1.Height / 2) - (Bmp.Height / 2)), Bmp.Width, Bmp.Height)
    
            Dim g As System.Drawing.Graphics = Me.CreateGraphics()
            Dim StrWidthHeight As System.Drawing.SizeF = g.MeasureString("Hello", New Font("Cambria", 24))
            g.Dispose()
    
            grafx.Graphics.DrawString("Hello", New Font("Cambria", 24), Brushes.DodgerBlue, CInt((Panel1.Width / 2) - (StrWidthHeight.Width / 2)), CInt((Panel1.Height / 2) + (Bmp.Height / 4)))
            grafx.Render()
    
        End Sub
    End Class
    


    La vida loca

    Thursday, July 17, 2014 4:43 AM
  • Well I've been messing around with moving panels and pictureboxes. But stuck with a double buffered panel in the first two images below.

    So when you move the mouse what happens is the mouse stays centered in the Form but the panel moves. If you move the mouse then the panel moves in the opposite direction. So if you move the mouse right the cursor gets centered in the Form automatically but the panel moves left.

    I added an image that stays centered in the Form that analogizes a player perhaps. Note that it has moved down the panel (actually the panel moved up instead) as can be seen by the numbers drawn in the background.

    But to me it seems like a lot of effort to move a panel for no reason.

    In the bottom image is a Form. All around it is empty space. However using Buffered Graphics which is much cleaner then standard graphics I believe all those red images, being used as examples, could be drawn out in space. And when the mouse is moved then each of those images drawing coordinates are just altered and the Form is refreshed. The Form doesn't even need to be set to double buffered when using buffered graphics.

    So sometime today I'm going to take the code I already have and test that just using a Form with no panel or picturebox at all. Just moving drawings coordinates and see what happens. With one drawing alway staying centered in the Form, as the player, as the other drawings move around it. And see how that works out. I believe it will be exceptionally faster and better. Although I will turn off the mouse cursor so it can't be seen as it interferes with the view.


    La vida loca

    Thursday, July 17, 2014 8:48 AM
  • I just tested Buffered Graphics using the Forms Paint event. The Form was not set to double buffered.

    A Bitmap was drawn at about 500, -100000. Then I ran a timer to add 10 to -100000 and refresh the Form. Also display -100000 going from negative to positive. The bitmap is 225 x 255 and when -100000 got to about -200 the bitmap began entering the top of the Form, under the titlebar and went down the Form off into the ether somewhere. Nice and smooth.

    So today sometime I'll post the code for that.


    La vida loca

    Thursday, July 17, 2014 9:10 AM
  • Here is another approach. This one just makes a big picturebox and moves it inside the form. I just put another picture box in the lower right to move with but you can use Razerz mouse and timer example.

    I drew 3 maps onto a memory bitmap and copied it into the big picturebox. The map is 2800 x 1500 pixels.

    Public Class Form4
        Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox1.Left = 0
            PictureBox1.Top = 0
    
            Using bmp1 As Bitmap = Bitmap.FromFile("C:\bitmaps\world maps\w1.png")
                Using bmp2 As Bitmap = Bitmap.FromFile("C:\bitmaps\world maps\w2.png")
                    Using bmp3 As Bitmap = Bitmap.FromFile("C:\bitmaps\world maps\w3.png")
                        Dim w As Integer = bmp1.Width + bmp2.Width + bmp3.Width
                        Using bmpall As Bitmap = New Bitmap(w, bmp1.Height)
                            Using g As Graphics = Graphics.FromImage(bmpall)
                                g.DrawImage(bmp1, 0, 0)
                                g.DrawImage(bmp2, bmp1.Width, 0)
                                g.DrawImage(bmp3, bmp1.Width + bmp2.Width, 0)
                                PictureBox1.Width = bmpall.Width
                                PictureBox1.Height = bmpall.Height
                                PictureBox1.Image = bmpall.Clone
                            End Using
                        End Using
                    End Using
                End Using
            End Using
        End Sub
    
        Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove
            Dim fx As Single = PictureBox1.Width / PictureBox2.Width
            Dim fy As Single = PictureBox1.Height / PictureBox2.Height
            PictureBox1.Left = fx * e.X - PictureBox1.Width
            PictureBox1.Top = fy * e.Y - PictureBox1.Height
        End Sub
    End Class

    Thursday, July 17, 2014 3:25 PM
  • Take a look at this article regarding zooming and panning an image:

    http://bobpowell.net/zoompicbox.aspx

    Thursday, July 17, 2014 9:56 PM
  • You think you were bored Mohenjo Daro then take a look at this.

    I went on the internet and downloaded two world maps.

    WorldMap1.Png is 7408 x 4176 pixels and 3.32 MB in size.

    WorldMap2.Png is 9864 x 5000 pixels and 3.34 MB in size.

    I already had Crossbones.Png which is 90 x 90 pixels and 11.4 KB in size.

    Temp Card folder contains images of a deck of playing cards and some other images for that deck. Its size is 476 KB so all of the images in it (79) total that amount in size.  All those images are loaded into a list of Bitmap but I've not figured out what to do with them yet.

    Rather than drawing on the Form or in a control I just draw on the desktops area of Screen.PrimaryScreen.WorkingArea.Width and Screen.PrimaryScreen.WorkingArea.Height which is smoother and faster.

    The code creates a drawing rectangle the size of the screens working area width and height.

    It crops whatever area of the WorldMap that needs to fit in that drawing rectangle. I've tested it with both World Maps.

    Then that area of the WorldMap is drawn on the desktop. After that Crossbones.Png is drawn in the center of the drawing rectangle over the top of whatever area of the WorldMap it is drawn over.

    The code uses a left mouse down to start the timer which starts the drawing which also creates a new transparent bitmap which replaces the cursor.Arrow with a transparent cursor.

    The current crop of the WorldMap image fills the drawing rectangle.

    Crossbones.Png is drawn in the center of the drawing rectangle.

    When the mouse is moved the pointer is actually relocated back in the center of the primary screens working area. But a new crop of the WorldMap is drawn depending on which way the mouse was moving. If the mouse was moving up then the WorldMap appears to be moving down, mouse moving left = WorldMap moving right, etc.

    If the mouse moves left so there is no more WorldMap left of that point to draw then the drawing rectangle becomes black past the point of WorldMap that it crops.

    A right mouse down stops the drawing which also returns the cursor to cursor.Arrow and allows the mouse pointer to be used again for other things.

    Using left mouse down or right mouse down can be removed and any other control could be used to start or stop the timer. However once the timer starts the mouse could not be used to select that control or anything else on the desktop even if the app was minimized and you used alt tab to tab to a different app. So watch out with that cause it caused me some significant headaches yesterday when I had to launch Task Manager and figure out how to shutdown the app without being able to use the mouse to do so.

    I haven't noticed any blinking or anything else with the drawing. The Crossbones.Png image, when the timer is on, stays centered and the drawing of the WorldMap moves opposite of what the mouse is trying to be moved. It's pretty nice really.

    The timers interval begins at 100 but I let the stopwatch reset its interval based on how long it takes the code in the timer to finish.

    Form code.

    Option Strict On
    
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        ' BufferedGraphics Class http://msdn.microsoft.com/en-us/library/system.drawing.bufferedgraphics(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
    
        Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As IntPtr) As IntPtr
    
        Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr
    
        <DllImport("user32.dll", SetLastError:=False)> _
        Private Shared Function GetDesktopWindow() As IntPtr
        End Function
    
        <DllImport("user32.dll", EntryPoint:="RedrawWindow")> _
        Private Shared Function RedrawWindow(ByVal hWnd As IntPtr, ByRef lprcUpdate As RECT, ByVal hrgnUpdate As IntPtr, ByVal flags As UInteger) As Boolean
        End Function
    
        Private Const RDW_INVALIDATE As Integer = &H1
        Private Const RDW_ERASE As Integer = &H4
        Private Const RDW_UPDATENOW As Integer = &H100
    
        <StructLayout(LayoutKind.Sequential)> _
        Private Structure RECT
            Public left, top, right, bottom As Integer
        End Structure
    
        Dim TimeIt As New Stopwatch
    
        Dim ObjectsToDraw As New List(Of Bitmap)
        Dim Bmp As Bitmap
        Dim WM1 As Bitmap
        Dim WM2 As Bitmap
        Dim Csr As New Bitmap(1, 1)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            Me.WindowState = FormWindowState.Maximized
            Me.DoubleBuffered = True
            Me.BackColor = Color.Aqua
            Bmp = New Bitmap("C:\Users\John\Documents\Visual Studio 2012\Drawing on Desktop - Like roll playing game\Crossbones.Png")
            WM1 = New Bitmap("C:\Users\John\Documents\Visual Studio 2012\Drawing on Desktop - Like roll playing game\WorldMap1.Png")
            WM2 = New Bitmap("C:\Users\John\Documents\Visual Studio 2012\Drawing on Desktop - Like roll playing game\WorldMap2.Png")
            For Each Item In My.Computer.FileSystem.GetFiles("C:\Users\John\Documents\Visual Studio 2012\Drawing on Desktop - Like roll playing game\Temp Card Folder")
                ObjectsToDraw.Add(New Bitmap(Item))
            Next
            Csr.MakeTransparent()
            Timer1.Interval = 100
            CBx = CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Bmp.Width / 2))
            CBy = CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Bmp.Height / 2))
        End Sub
    
        Private Sub Form1_FormClosing(sender As Object, e As EventArgs) Handles Me.FormClosing
            Dim r As New RECT
            r.left = 0
            r.top = 0
            r.right = Screen.PrimaryScreen.WorkingArea.Width
            r.bottom = Screen.PrimaryScreen.WorkingArea.Height
            RedrawWindow(GetDesktopWindow, r, GetDesktopWindow, RDW_ERASE And RDW_INVALIDATE And RDW_UPDATENOW)
        End Sub
    
        Dim IsLeftMouseButtonDown As Boolean = False
    
        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
            If e.Button = Windows.Forms.MouseButtons.Left Then
                IsLeftMouseButtonDown = True
                Me.Cursor = New Cursor(Csr.GetHicon)
            ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
                IsLeftMouseButtonDown = False
                Me.Cursor = Cursors.Arrow
            End If
        End Sub
    
        Dim DrawThemX As Integer = 0
        Dim DrawThemY As Integer = 0
        Dim CBx As Integer = 0
        Dim CBy As Integer = 0
        Dim Ex As Integer = 0
        Dim Ey As Integer = 0
        Dim MovedOnce As Boolean = False
        Dim Timer1Running As Boolean = False
    
        Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
            If Timer1Running = True Then Ex = e.X : Ey = e.Y
            If IsLeftMouseButtonDown = True And Timer1Running = False Then
                If MovedOnce = True Then
                    Try
                        If Ex < e.X Then DrawThemX -= (e.X - Ex)
                        If Ex > e.X Then DrawThemX += (Ex - e.X)
                        If Ey < e.Y Then DrawThemY -= (e.Y - Ey)
                        If Ey > e.Y Then DrawThemY += (Ey - e.Y)
                        Ex = e.X
                        Ey = e.Y
                        Timer1Running = True
                        Timer1.Start()
                    Catch ex As Exception
                    End Try
                Else
                    Cursor.Position = New Point(CInt(Screen.PrimaryScreen.WorkingArea.Width / 2), CInt(Screen.PrimaryScreen.WorkingArea.Height / 2))
                    Ex = e.X
                    Ey = e.Y
                    MovedOnce = True
                End If
            End If
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    
            TimeIt.Restart()
    
            Timer1.Stop()
    
            Cursor.Position = New Point(CInt(Screen.PrimaryScreen.WorkingArea.Width / 2), CInt(Screen.PrimaryScreen.WorkingArea.Height / 2))
    
            Dim grafx As BufferedGraphics
            Dim context As BufferedGraphicsContext
    
            context = BufferedGraphicsManager.Current
    
            grafx = context.Allocate(Graphics.FromHwnd(GetDesktopWindow), New Rectangle(0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height))
    
            Dim CropWorldMap As New Rectangle(DrawThemX, DrawThemY, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
    
            grafx.Graphics.DrawImage(WM2, New Rectangle(0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height), CropWorldMap, GraphicsUnit.Pixel)
    
            grafx.Graphics.DrawImage(Bmp, CBx, CBy, Bmp.Width, Bmp.Height)
    
            grafx.Render()
    
            grafx.Dispose()
            context.Dispose()
    
            Timer1Running = False
            Timer1.Interval = CInt(TimeIt.ElapsedMilliseconds) + 5
            TimeIt.Stop()
            Cursor.Position = New Point(CInt(Screen.PrimaryScreen.WorkingArea.Width / 2), CInt(Screen.PrimaryScreen.WorkingArea.Height / 2))
        End Sub
    
    End Class

    Image of WorldMap1 after mouse had "moved" to current location on it.

    Image of WorldMap2 after mouse had "moved" to current location on it.


    La vida loca







    Friday, July 18, 2014 2:16 AM
  • So Mohenjo Daro with all of the information provided were you able to find an answer to your issue?

    Since you've not proposed any post as an answer do you still need assistance in some fashion?

               
                                                       


    La vida loca


    Saturday, July 19, 2014 4:36 AM
  • Just for kicks I deleted my last animated .Gif post, increased the size of one of the world maps using GIMP so that it is now 15000 x 8456 pixels in size, 9.91 MB of info and used that.

    I could have made the image larger than that but GIMP needed 1.2GB of RAM to make it to 15000 x 8456 and I checked Resource Monitor which said I had 1.3GB available so that was the largest I could do. After the file is saved as a .PNG it's much smaller than 1.2GB obviously (9.91 MB). I NEED MORE RAM!

    The below animated .Gif again shows 300 x 300 pixel images of the desktop which were reduced to 150 x 150 which allows the animated .Gif to contain 210 layers. So it runs longer. From Canada to the Caribbean. :)

    Next up. Rotate the crossbones bitmap as the image beneath it moves so crossbones head points against the direction the image beneath it appears to be moving. As if crossbones was moving in the opposite direction like a player would.


    La vida loca



    Saturday, July 19, 2014 8:45 AM
  • Yes, my question has been answered, in a few ways, thanks for all the help in this!
    Saturday, July 19, 2014 2:02 PM