How to make simple button that open a picture

Daniel Mouyal 21 Reputation points
2021-04-30T14:51:40.37+00:00

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");

second

System.Diagnostics.Process.Start("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
    2021-04-30T21:24:08.433+00:00

    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

    System.Diagnostics.Process.Start("real.png");
    

    will display the image.

    • Wayne
    0 comments No comments

  2. WayneAKing 4,921 Reputation points
    2021-04-30T22:45:54.09+00:00

    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

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

    or use a "verbatim string"

    Process.Start(@"C:\windows\system32\rundll32.exe",  
        @"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.

    Process.Start("C:\windows\system32\rundll32.exe",  
        "C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen " _  
        & "C:\Test Dir\real.png")  
    
    • Wayne
    0 comments No comments