I have loaded a map in picture box, but I can't move around it (to see the whole area of the map)
Can someone help me...

Dani AI

Generated

As noted, the desktop WinForms fixes suggested earlier by and won't necessarily carry over to a Pocket PC/Compact Framework app. On those devices it is more reliable to implement simple, manual panning: draw the map into a control and move a viewport offset in response to stylus/mouse drags. That keeps memory use predictable and gives smooth control on devices where some WinForms helpers are limited.

Example (VB.NET Compact Framework) — put this in a UserControl or Form and call LoadMap with a Bitmap:

' class-level
Private mapBmp As Bitmap = Nothing
Private offset As Point = New Point(0, 0)
Private lastPt As Point
Private dragging As Boolean = False

Public Sub LoadMap(bmp As Bitmap)
  mapBmp = bmp
  offset = New Point(0, 0)
  Me.Invalidate()
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  MyBase.OnPaint(e)
  If mapBmp IsNot Nothing Then
    e.Graphics.DrawImage(mapBmp, -offset.X, -offset.Y)
  End If
End Sub

Private Sub Me_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseDown
  dragging = True
  lastPt = e.Location
End Sub

Private Sub Me_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove
  If Not dragging OrElse mapBmp Is Nothing Then Return
  Dim dx = e.X - lastPt.X
  Dim dy = e.Y - lastPt.Y
  offset.X = Math.Max(0, Math.Min(Math.Max(0, mapBmp.Width - Me.ClientSize.Width), offset.X - dx))
  offset.Y = Math.Max(0, Math.Min(Math.Max(0, mapBmp.Height - Me.ClientSize.Height), offset.Y - dy))
  lastPt = e.Location
  Me.Invalidate()
End Sub

Private Sub Me_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseUp
  dragging = False
End Sub

Tips: clamp offsets so the viewport never runs past the image edges; dispose large Bitmaps when done; for very large maps serve tiles or reduced-resolution images to avoid low-memory crashes; test on an actual device (emulator memory/performance differs). If zooming is required, scale the draw and adjust offsets after scaling so the same point stays under the stylus.

Recommended Answers

All 4 Replies

Put a panel control on your form and set its AutoScroll property to true. Now add your picturebox to this panel and set is SizeMode to AutoSize

Doing what waynespangler said would work but it would change the total size of your picturebox. To keep the size of the picturebox the same but fit your picture into the picturebox do this, in the properties of your Picture box set "size mode" to "zoom"

Thnx,

pete

Guys,

I have tried it on the WinForm, but I need it for PocketPC app. It doesen't work there. Do You have some clues?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.