效果:点击button1程序完全全屏(包括任务栏的位置),点击button2程序还原。
打开vs2005或2008,新建一个窗口form1,在窗口上加入两个按钮button1和button2。然后打开form1.cs,将下列代码复制进去。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
private const int SW_HIDE = 0;
private const int SW_SHOW = 1;
[DllImport("user32.dll")]
private static extern int FindWindow(string className, string windowText);
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int command);
private FormWindowState winState;
private FormBorderStyle brdStyle;
private bool topMost;
private Rectangle bounds;
private bool IsMaximized = false;
public void Maximize()
{
if (!IsMaximized)
{
IsMaximized = true;
this.Save();
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
WinApi.SetWinFullScreen(this.Handle);
}
}
public void Save()
{
winState = this.WindowState;
brdStyle = this.FormBorderStyle;
topMost = this.TopMost;
bounds = this.Bounds;
}
public void Restore()
{
this.WindowState = winState;
this.FormBorderStyle = brdStyle;
this.TopMost = topMost;
this.Bounds = bounds;
IsMaximized = false;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int hWnd = FindWindow("Shell_TrayWnd", "");
ShowWindow(hWnd, SW_SHOW);
this.Maximize();
}
private void button2_Click(object sender, EventArgs e)
{
this.Restore();
}
}
public class WinApi
{
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int which);
[DllImport("user32.dll")]
public static extern void
SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int X, int Y, int width, int height, uint flags);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private static IntPtr HWND_TOP = IntPtr.Zero;
private const int SWP_SHOWWINDOW = 64; // 0×0040
public static int ScreenX
{
get { return GetSystemMetrics(SM_CXSCREEN);}
}
public static int ScreenY
{
get { return GetSystemMetrics(SM_CYSCREEN);}
}
public static void SetWinFullScreen(IntPtr hwnd)
{
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
}
}
}
以上代码vs2008c#通过。
简单的,去下面看吧,刚给你写的
http://www.zu14.cn/2009/03/13/csharp-show-hide-taskbar-by-api/