How to make simple button that open a picture

Daniel Mouyal 21 Reputation points

Hello to all users that can help me I am new in the visual studio I try to make do Simple forum that contains Button and I want to do a simple function when I press on the button it will open a picture that I have in the resources folder very simple but I try 2 methods but I get an error this is the methods

Process.Start("C:\windows\system32\rundll32.exe", "C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen " & "real.png");



so please if somebody can help me it will be great

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,798 questions
{count} votes

2 answers

Sort by: Most helpful
  1. WayneAKing 4,921 Reputation points

    The operating system doesn't know where the .png file
    is located, so you have to tell it. By default it will
    look in the current folder. When testing from the VS
    IDE that will be the folder where your program's exe
    is located. Such as ...\bin\debug or ...\bin\release

    If you put the png in one of those folders then you
    will find that the code you posted


    will display the image.

    • Wayne
    0 comments No comments

  2. WayneAKing 4,921 Reputation points

    Your first code example has several problems, depending
    on which language is being used:

    (1) In C# the backslash is called an "escape character"
    when it is used alone. To use it as an actual backslash
    character in a source code string you have to double it

        "C:\\WINDOWS\\System32\\shimgvw.dll,ImageView_Fullscreen "  
        + "C:\\Test Dir\\real.png");  

    or use a "verbatim string"

        @"C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen "   
        + @"C:\Test Dir\real.png");  

    (2) In VB this is not necessary, but note that there is
    no semicolon at the end.

        "C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen " _  
        & "C:\Test Dir\real.png")  
    • Wayne
    0 comments No comments