Click here to Skip to main content
15,920,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a panel in a windows form. I want to display the desktop inside the panel. Can anybody please tell me how to do it.
thank you in advance
Posted
Comments
Sergey Alexandrovich Kryukov 22-Jun-11 16:01pm    
What does it mean: display desktop. Desktop is desktop, it's always "displayed". What is displayed in your panel could not be a "desktop", but what do you want there?
--SA
manabjn 22-Jun-11 16:12pm    
I want to display all shortcuts in the desktop inside a panel. Is it possible. Please tell me.
Thank you
Sergey Alexandrovich Kryukov 22-Jun-11 16:58pm    
Now I see. Please see my solution.
--SA

you can use Environment.GetFolderPath Method[^] and pass the argument as Environment.SpecialFolder.Desktop. That gives you the path for desktop.

With that you can get the files and folders on the desktop and display it in the panel.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Jun-11 16:43pm    
Correct, my 5.
--SA
Sergey Alexandrovich Kryukov 22-Jun-11 16:57pm    
However, there is a lot more to it.
Please see my solution.
--SA
In addition to correct solution by Vivek:

There are more to it.

1) Use Environment.GetFolderPath with Environment.SpecialFolder.Desktop to get access to a desktop directory, see http://msdn.microsoft.com/en-us/library/14tx8hby.aspx[^].

2) Use System.IO.Directory.GetFiles to get the full path names all the files you need. Be careful: there is a problem here, the resolution is explained here:
Directory.Get.Files search pattern problem[^].

3) Populate your panel with some controls you want to devise to represent a file on a desktop; probably you need to have each control clickable to do the actions a link on the real desktop usually does.

4) To implement the previous item, you will need to get access to *.LNK files which are most typically stored in the desktop. You will need P/Invoke to do that; see the code sample here:
http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c[^].

5) Your application will need to respond to changes on the desktop as the user can add, modify or remove some files. To handle those changes, you need some events triggering in your software. This is not very trivial. For this purpose, use the class System.IO.FileSystemWatcher, see http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^].

That's it, it looks like. Please let me know if you have any problems implementing all this. If you do, I would also like to know your ultimate goals and the purpose of this application. Why doing what the real desktop is already doing?

Good luck,
—SA
 
Share this answer
 
Not sure if this will work with the Desktop, but perhaps getting the desktop's handle and calling SetParent function - see this article[^] for a demonstration of hosting windows/apps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900