PictureBoxes and Buttons

Posted on 2004-11-11
Last Modified: 2010-04-24

I'm new to the whole Visual Basic .NET. I have been using VB6 for awhile. I was wondering, how do you make it so in your form you click a command button and it loads an image from the harddrive into the picture box (e.g. "C:\test.jpg"). Code would help, thanks.
Question by:Linky
    LVL 25

    Accepted Solution

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            picturebox1.image = image.fromfile("c:\test.jpg")
        End Sub
    LVL 27

    Assisted Solution


    Here is where I found good examples for getting started in VB.Net


    Link for ASP programs...

    sample code a find and open a file

      Public Sub OpenImages()
            Dim i As Short
            Dim myOpenFileDialog As New OpenFileDialog
            With myOpenFileDialog
                .CheckFileExists = True
                .DefaultExt = "bmp"
                .Filter = "Icon files(*.ico)|*.ico"
                .Filter += "|Bmp files (*.bmp)|*.bmp"
                .Filter += "|Jpeg files(*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg"
                .Filter += "|Gif files(*.gif)|*.gif"
                .Filter += "|Tif files(*.tif;*.tiff)|*.tif"
                .Filter += "|Png files(*.Png)|*.Png"
                .InitialDirectory = "c:\"
                .Multiselect = False
            End With
            ' Use the OpenFileDialog and put the path and name of the selected file in a var.
            If myOpenFileDialog.ShowDialog = DialogResult.OK Then
                sFileName = myOpenFileDialog.FileName
                sIconPath = Path.GetDirectoryName(sFileName) & "\"
                i = sFileName.LastIndexOf("\") + 1
                sFileName = sFileName.Substring(i)
            End If
        End Sub
    LVL 2

    Author Comment

    Thank you both, I need to play with .NET looks interesting and fun.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now