PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Problem sending a pic to a picturebox.-VBForums
Results 1 to 5 of 5

Thread: Problem sending a pic to a picturebox.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    70

    Problem sending a pic to a picturebox.

    I have a folder of JPG mages located in the same folder where the SLN file is.
    How do I use code to display said pictures pictureboxs?

    Can I establish the path to said folder? It doesn't have to be in that location. It just has to have easy access.
    Last edited by GarySut; Apr 10th, 2017 at 05:16 PM. Reason: clarity

  2. #2
    Hyperactive Member Vexslasher's Avatar
    Join Date
    Feb 2010
    Posts
    429

    Re: Problem sending a pic to a picturebox.

    Well if you just trying to get a few images into picture boxes then you could do something like this. The CurDir() will provide the folder that your program is being run from.
    vb.net Code:
    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2.         PictureBox1.ImageLocation = CurDir() & "\" & "FileName.jpg"
    3.     End Sub

    If you wanted to display all the images in the folder similar to how they look within the folder you can add a view like that using a ListView.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2017
    Posts
    70

    Re: Problem sending a pic to a picturebox.

    Quote Originally Posted by Vexslasher View Post
    Well if you just trying to get a few images into picture boxes then you could do something like this. The CurDir() will provide the folder that your program is being run from.
    vb.net Code:
    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2.         PictureBox1.ImageLocation = CurDir() & "\" & "FileName.jpg"
    3.     End Sub

    If you wanted to display all the images in the folder similar to how they look within the folder you can add a view like that using a ListView.


    I just knew it would be an easy reply. I forgot about CurDir().

    I made the mistake of asking in another forum and I received all sorts of complexity such as timers and VB settings along with about 15 lines of code...

    Thanks, I will check it out.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,618

    Re: Problem sending a pic to a picturebox.

    Of course if your pictures are in your .sln directory, that would usually be three directories up from the executable.
    Assuming Vexslasher's code is correct...
    Code:
            PictureBox1.ImageLocation = CurDir() & "\..\..\..\" & "FileName.jpg"
    Also assumes you don't start the program from another program or batch file, which may make the curdir where the batch file or launching program is, not where the executable you're running resides.

    If you use Application.ExecutablePath instead of CurDir, that will return where the executable is, not what the curdir happens to be.
    Last edited by passel; Apr 10th, 2017 at 06:14 PM.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,293

    Re: Problem sending a pic to a picturebox.

    I'd suggest that, as a longer term solution, you look into the Windows special folders:

    https://msdn.microsoft.com/en-us/lib...v=vs.100).aspx

    The reason for doing this is just that, as passel suggests, things move about. During development, the program will be in one place, after deployment (if this is a program that will actually be deployed), then it will be somewhere else. CurDir is convenient because it gives you "this here directory!", and that's what the special folders do, as well, except that "this here directory" depends on where the application is running from, which can change. By using the special folders, you have something that is more wordy than CurDir, but does effectively the same thing, and it won't be moving around on you. Of course, if this is just for testing, or single use, and will never be deployed, this doesn't matter.
    My usual boring signature: Nothing

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width