By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

Context Menu for PictureBoxes

P: n/a
Hello All,

I have several Pictureboxes (linked to an AccessDB) on a VB.NET form. I
would like to use a context menu to allow the user to open the picture in
their default picture viewer or editor. I'd like to use the same default
viewer/editor and open with... choices that are present on the users
computer.

Does anyone know how I can find this information programatically, so my
picturebox context menu uses the same settings as the system context menu
for pictures?

Thanks!!

Lee
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi

The System Context Menu is worked with Shell(Explorer.exe), so we need to
save the picture to a disk file first, or the Explorer.exe and even the
following picture viewer program will not know where to load the file.

And then we can use the syntax below to spawn a process to do the job.
rundll32.exe shell32.dll,OpenAs_RunDLL "C:\test.txt"

You may try to take a look at the link below.
http://groups.google.co.jp/groups?hl...42NHpEHA.1992%
40TK2MSFTNGP09.phx.gbl&rnum=1&prev=/groups%3Fq%3Dopenwith%2520dialog%2520%25
22c%2523%2522%26hl%3Dzh-CN%26lr%3D%26sa%3DN%26tab%3Dwg

Also in windows xp, there will be additional dialog asked for if you want
to search the programs on the internet, if you do not want it, you may try
to use the registry below to disable it.

This can be disabled in the registry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Explorer]
"InternetOpenWith"="FALSE"

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2

P: n/a
lgbjr,

Drag from the toolbox a "contextmenu" on your form,
Than fill that as a normal menu by clicking on it (It appears in top of your
form).
Than set in the properties of your picturebox in the property contextmenu
(that will be added because you draged that contextmenu on your form) the
name of that contextmenu.

Than it works in my opinion.

I hope this helps?

Cor
Nov 21 '05 #3

P: n/a
Cor,

Thanks for the reply. Adding the context menu for a particular control and
adding items to the control is not the question. That is easy. Depending on
how the user has their system setup, when they right click on a picture (in
Explorer), and select the Open command, there is a default program that the
system uses, or if they select Open with... there is a list of recommended
programs, plus an entry for Choose program.

I want the context menu that I use for the pictures in my app to have the
same default open program and the same list of programs for Open With. I'm
assuming this information is in the registry somewhere, but I don't know
where. Once I know where to look, I can set the actions for my context menu
at runtime.

Regards,
Lee

"Cor Ligthert" <no************@planet.nl> wrote in message
news:eS****************@TK2MSFTNGP12.phx.gbl...
lgbjr,

Drag from the toolbox a "contextmenu" on your form,
Than fill that as a normal menu by clicking on it (It appears in top of
your form).
Than set in the properties of your picturebox in the property contextmenu
(that will be added because you draged that contextmenu on your form) the
name of that contextmenu.

Than it works in my opinion.

I hope this helps?

Cor

Nov 21 '05 #4

P: n/a
Hi All,

OK, before I start coding, I want to make sure the process I need to use is
correct. I want the context menu in my app to look/act the same as the
system context menu for any given object. So, as an example, I want to setup
a context menu for a picturebox.

Let's say that I limit the contents of the picturebox to JPG files. So, when
the user right clicks on the picturebox, I need to look at the registry
(HKEY_ClASSES_ROOT) entry for .jpg (Default Value). If the user has not
added any Graphics packages to his system, the Default Value will be
jpegfile. I then go to the jpegfile registry entry (still in
HKEY_CLASSES_ROOT) and look at the shell subkey. The shell subkey may have
some subkeys like Open, Edit, Preview. I add these menu items to my context
menu. Whatever the command values are for these subkeys will be what I need
to use for each item in my context menu.

If the user has added some programs to the system, the default value for the
..jpg key may not be jpegfile. For instance, if the user has added ACDSee,
the default value might be ACDSee.jpg. In this case, I would go to that
registry entry and look at the shell subkeys.

In all cases I'll need to create a temporary copy of the image (maybe
something like C:\Temp\pictureboxname.jpg), then use the temp jpg file for
whatever action the user requested.

Now, I want to delete this temp jpg file when the user finishes doing
whatever they wanted to do (open, edit, preview, etc). So, I'll need to
create a thread for whatever command is executed, and when the thread
terminates I can delete the temp file. If the user selected the edit item,
when the thread terminates, I'll need to load the temp jpg file back to the
picturebox first, then delete the temp file.

Keeping in mind that I want the context menu in my app to provide the same
functions as the system context menu, does this process make sense, or am I
missing a much simpler way to accomplish the same thing?

Regards and TIA,
Lee

"lgbjr" <lg***@online.nospam> wrote in message
news:OR**************@tk2msftngp13.phx.gbl...
Hello All,

I have several Pictureboxes (linked to an AccessDB) on a VB.NET form. I
would like to use a context menu to allow the user to open the picture in
their default picture viewer or editor. I'd like to use the same default
viewer/editor and open with... choices that are present on the users
computer.

Does anyone know how I can find this information programatically, so my
picturebox context menu uses the same settings as the system context menu
for pictures?

Thanks!!

Lee

Nov 21 '05 #5

P: n/a
Hi,

I think it is hard to make the identity context menu with system one,
because many of whose implement is depent on the Shell(Explorer.exe).
e.g. the winrar is a shell extension, it is registered in the register as a
shell extension which is only used by the explorer.exe.

Anyway I think we can try to make it as similar with the system one as
possible.
From the KB,
How to Remove Programs from the "Open With" List
http://support.microsoft.com/?id=258860

In addition to what you mention about the .jpg and jpeg key in the
HKEY_CLASSES_ROOT, we may also try to query the keys below to get the
OpenWith dialog.
1. HKEY_CLASSES_ROOT\.jpeg\OpenWithList
2. HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\
Explorer\FileExts\.extension\OpenWithList

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.