Hi Daniweb,

I have posted the question before also but for more clarity I posting my question again. Request a quick positive response.
I have googled a lot but not getting the information whcih I required.

I have a Picture box with the size of 1300, 350.
From one particular folder I want browse Images (.JPG).
I want browse these images with Keyboard shortcuts. Previous-F9, Next-F10, FirstImage-F11, LastImage-F12
If the image is bounding outside of the fixed lenght of the picture box I want scroll through the image.
Any Image I am loading width should be = 100% of the Picture Box layout

By the way I am using VS2013.

Guys, waiting for the quick responses.

Thanks.

Dani AI

Generated

Quick summary and a concrete approach that addresses the issues in 's sample and follows 's System.IO suggestion: collect image file paths with Directory.GetFiles, keep a current index, set the form's KeyPreview = True, and handle F9/F10/F11/F12 to move the index and call a single image-loading routine. Place the PictureBox inside a Panel with AutoScroll = True so images that exceed the displayable area can be scrolled programmatically.

A safe LoadImage routine (avoids file locks and preserves aspect ratio so the image width equals the container width):

Private Sub LoadImage(idx As Integer)
    If files Is Nothing OrElse idx < 0 OrElse idx >= files.Length Then Return
    Using fs As New IO.FileStream(files(idx), IO.FileMode.Open, IO.FileAccess.Read)
        Dim src = Image.FromStream(fs)
        Dim targetW = Panel1.ClientSize.Width
        Dim scale = targetW / src.Width
        Dim newW = CInt(src.Width * scale)
        Dim newH = CInt(src.Height * scale)
        If PictureBox1.Image IsNot Nothing Then PictureBox1.Image.Dispose()
        PictureBox1.SizeMode = PictureBoxSizeMode.Normal
        PictureBox1.Width = newW
        PictureBox1.Height = newH
        PictureBox1.Image = New Bitmap(src, newW, newH)
    End Using
End Sub

Keyboard handling (form-level; F9=prev, F10=next, F11=first, F12=last) plus simple horizontal scrolling using the Panel:

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
    Select Case e.KeyCode
        Case Keys.F9 : currentIndex = Math.Max(0, currentIndex - 1) : LoadImage(currentIndex)
        Case Keys.F10 : currentIndex = Math.Min(files.Length - 1, currentIndex + 1) : LoadImage(currentIndex)
        Case Keys.F11 : currentIndex = 0 : LoadImage(currentIndex)
        Case Keys.F12 : currentIndex = files.Length - 1 : LoadImage(currentIndex)
        Case Keys.Left
            Dim x = Math.Max(0, -Panel1.AutoScrollPosition.X - 50)
            Panel1.AutoScrollPosition = New Point(x, -Panel1.AutoScrollPosition.Y)
        Case Keys.Right
            Dim x = Math.Min(PictureBox1.Width - Panel1.ClientSize.Width, -Panel1.AutoScrollPosition.X + 50)
            Panel1.AutoScrollPosition = New Point(x, -Panel1.AutoScrollPosition.Y)
    End Select
End Sub

Troubleshooting notes: set Form.KeyPreview = True so F-keys are caught; check modifier/key logic (use e.Control AndAlso e.KeyCode = Keys.O rather than comparing Keys.Control to True); include common extensions (".jpg", ".jpeg") and compare case-insensitively; always dispose old Image to avoid memory leaks and file locks; use SearchOption.AllDirectories only if recursive search is required.

Recommended Answers

All 2 Replies

Hi,

Have you attempted any of this yourself? Where is your code and what errors did you get?

  1. Use System.IO to browse the folder
  2. Use a menubar with the buttons linked to the shortcuts to "navigate"

Yesterday, I made the code but I have deleted that. Now I am trying to create the new one. But not working.
I am just starting now.

I have alredy imported the System.IO

look at the below code.

rivate Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Control Or e.KeyCode = Keys.O Then
            If (FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) = True Then
                Dim f As String = FolderBrowserDialog1.SelectedPath
                Form2.ListBox1.Items.Add(GetFiles("*.JPG"))
                Form2.Show()
            End If
        End If
        If e.KeyCode = Keys.Control = True Or e.KeyCode = Keys.LShiftKey = True Or e.KeyCode = Keys.I = True Then
            Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            Me.PictureBox1.Width = 1299
        End If
    End Sub
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.