question

DanielMouyal-8389 avatar image
0 Votes"
DanielMouyal-8389 asked WayneAKing-0228 edited

How to make simple button that open a picture

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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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

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

Are you working with C# (C Sharp) or VB (Visual Basic)?

Since the example code lines you posted end with a
semi-colon, it appears to be C#. But as you are using
an ampersand (&) to concatenate two strings it looks
more like VB.

  • Wayne

0 Votes 0 ·
WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered WayneAKing-0228 edited

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.