Results 1 to 7 of 7

Thread: Is it possible to load pictures without an openfiledialog?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    14

    Question Is it possible to load pictures without an openfiledialog?

    Ok so i know that i can load a picture into a picturebox without an openfiledialog. What i want to do is this. Keeping it simple, I have 2 forms. on the first form, i have a picturebox, some textboxes and buttons bla bla bla. the user loads a picture (from their computer) into the picturebox, types some info into the textboxes, and clicks the button to save all text and the picture to a folder that I specify (via savefiledialog). that all works perfectly fine.
    now they open the second form. the second form has a picturebox and 4 buttons. I kinda set it up like a tv lol. the first button turns on the "tv" (picturebox) on, and the second and third buttons i want to scroll through pictures without opening the dialog everytime.

    Is this possible? Im trying to make it like a windows photo gallery kind of thing. with "previous" and "next" buttons where whatever picture from the folder that is displayed, when u click next it will go to the next picture in that folder. and when they get to the last picture, it will start over with the first one.

    for the folder that i specify im using the following code

    Code:
    application.startupPath & "\logs\"
    Can anyone please help me? thanks in advance!

    Brian

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Is it possible to load pictures without an openfiledialog?

    vbnet Code:
    1. '
    2.         'Get a list of all JPG files in the specified folder
    3.         Dim JPGFiles As String() = System.IO.Directory.GetFiles(Application.StartupPath + "\logs", "*.jpg")

    The above code would get you a list of all Jpeg files in your logs folder. You already know how to use a file name to load an image so I assume you know where to go from there.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Is it possible to load pictures without an openfiledialog?

    If you're wanting to avoid having your program lock the image file, I would suggest you use a FileStream to read all of the bytes of the file into a Byte array, you can convert the byte array into an image object in your program anytime you want, for example, you read all of the bytes into the array, then assign a cast of that array to an image to the picturebox's image property.
    Also by doing it this way, you can turn around and store the bytes in a database too.

    Convert Image File to Bytes and Back - CodeProject
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    14

    Re: Is it possible to load pictures without an openfiledialog?

    Niya, i tried to figure it out on my own but i cant im still a noob. Would I use 'count' with that? as to pull up the first file in that folder? i cant really give the file a name since the name is up to the user. im lost sorry.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    14

    Re: Is it possible to load pictures without an openfiledialog?

    Im still a little lost here. can anyone help?

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Is it possible to load pictures without an openfiledialog?

    How could it be up to the user and you're not using an OpenFileDialog ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Is it possible to load pictures without an openfiledialog?

    hi Glasner,

    Maybe I'm understanding your question differently. I suggest you go about it like this.

    1. On the first form ("Form1") define a list to hold the image file names. Make it Public so you can access it from the other form ("Form2").
    Code:
    Public SelectedImages As New List(Of String)
    2. Each time the user saves an image to your specified folder, add the file name of the image to the list with SelectedImages.Add(filename).

    3. On Form2, declare an Integer variable to track the image.
    Code:
    Dim imgIndex As Integer = 0
    4. When the user turns on the "TV", set the picture box ("PictureBox1") to show the first image in the list:
    Code:
    PictureBox1.ImageLocation = Form1.SelectedImages(0)
    5. Put this in the Click sub of the "Next" button:
    Code:
    If imgIndex < Form1.SelectedImages.Count - 1 Then
      imgIndex+=1
    End If
    PictureBox1.ImageLocation = Form1.SelectedImages(imgIndex)
    6. Put this in the "Previous" button's Click sub:
    Code:
    If imgIndex > 0 Then
      imgIndex-=1
    End If
    PictureBox1.ImageLocation = Form1.SelectedImages(imgIndex)
    BB

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width