I want my application to have a button that hides and reexits the Windows taskbar in C # to block user access to it. Any suggestions?
I want my application to have a button that hides and reexits the Windows taskbar in C # to block user access to it. Any suggestions?
As they said, it is very complicated to do, but not impossible. Add a new class with the following code:
using System; using System.Runtime.InteropServices;
public class Taskbar
{
[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
[DllImport("user32.dll")]
public static extern int FindWindowEx(int parentHandle, int childAfter, string className, int windowTitle);
[DllImport("user32.dll")]
private static extern int GetDesktopWindow();
private const int SW_HIDE = 0;
private const int SW_SHOW = 1;
protected static int Handle
{
get
{
return FindWindow("Shell_TrayWnd", "");
}
}
protected static int HandleOfStartButton
{
get
{
int handleOfDesktop = GetDesktopWindow();
int handleOfStartButton = FindWindowEx(handleOfDesktop, 0, "button", 0);
return handleOfStartButton;
}
}
private Taskbar()
{
// hide ctor
}
public static void Show()
{
ShowWindow(Handle, SW_SHOW);
ShowWindow(HandleOfStartButton, SW_SHOW);
}
public static void Hide()
{
ShowWindow(Handle, SW_HIDE);
ShowWindow(HandleOfStartButton, SW_HIDE);
}
}
Show () shows and Hide () hidden.
Hiding the unhide task is a tricky thing, mainly because it's not something applications can simply go around doing. Otherwise it would be easy to make it a mess.
What you want is to keep your application screen full and this is very simple . It is only necessary to maximize form , remove the borders and set the TopMost
property to true
.
Example:
// colocar o form em full screen
private void btFullScreen_Click(object sender, EventArgs e)
{
TopMost = true;
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
}
// Voltar ao estado normal (barra tarefas aparecendo)
private void btRestaurar_Click(object sender, EventArgs e)
{
TopMost = false;
FormBorderStyle = FormBorderStyle.FixedSingle; // ou a que estava antes
}