Windows Forms: Hide and Show desktop icons in C#

This post shows you How to Hide and Show Desktop Icons in C#. NET Windows Forms Application.

How to hide desktop icons programmatically?

Using the Win32 API function you can easily to hide and show desktop icons in c#.

To hide desktop icons from c#. First of all, you should create a simple GUI that allows you to hide and display all the icons on the screen as shown below.

hide desktop icons in c#

After finishing your form design, you need to add the ShowWindow and FindWindowEx methods to your winform.

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

The DLLImport ("user32.dll") must have the name of C++ and Parentheses indicate that we are using an attribute.

Add the click event handler to the Show button allows you to show desktop icons.

private void btnShow_Click(object sender, EventArgs e)
{
    IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", null);
    ShowWindow(hWnd, 5);
}

Finally, Add the click event hanlder to the Hide button allows you to hide desktop icons.

private void btnHide_Click(object sender, EventArgs e)
{
    IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", null);
    ShowWindow(hWnd, 0);
}

and don't forget to include the namespaces below to your form.

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

Through the example above i show you how to hide or show desktop icons programmatically in c#.

Related Posts