C#winform程序窗口全屏是否遮盖任务栏问题
在作winform程序时遇到窗口如果全屏时,遮盖任务栏的问题,从网上搜到如下解决办法,与各位共享。以下代码本人都试过,没问题:
1.
执行如下按钮事件
private void btnFormMax_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.WindowState = FormWindowState.Maximized;
}
}
窗体最大化时 非全屏 不会遮盖任务栏
此时this.FormBorderStyle 默认为 Sizable
2.
执行如下按钮事件
private void btnFormMax_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
}
窗体最大化时 会全屏 及遮盖任务栏
此时this.FormBorderStyle 为 None 不会显示窗体标题栏等相关
3.
执行如下按钮事件
private void btnFormMax_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.FormBorderStyle = FormBorderStyle.None;
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.WindowState = FormWindowState.Maximized;
}
}
窗体最大化时 非全屏 不会遮盖任务栏
此时this.FormBorderStyle 为 None 不会显示窗体标题栏等相关。
[转]窗体最大化的时候,如何指定窗体的位置、大小(C#) https://www.360docs.net/doc/4c11404818.html,/adandelion/archive/2008/04/03/1136198.html
using System;
using System.Collections.Generic;
using https://www.360docs.net/doc/4c11404818.html,ponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class FormRegion : Form
{
private const long WM_GETMINMAXINFO = 0x24;
public struct POINTAPI
{
public int x;
public int y;
}
public struct MINMAXINFO
{
public POINTAPI ptReserved;
public POINTAPI ptMaxSize;
public POINTAPI ptMaxPosition;
public POINTAPI ptMinTrackSize;
public POINTAPI ptMaxTrackSize;
}
public FormRegion()
{
InitializeComponent();
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_GETMINMAXINFO)
{
MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
mmi.ptMinTrackSize.x = this.MinimumSize.Width;
mmi.ptMinTrackSize.y = this.MinimumSize.Height;
if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0)
{
m
mi.ptMaxTrackSize.x = this.MaximumSize.Width;
mmi.ptMaxTrackSize.y = this.MaximumSize.Height;
}
mmi.ptMaxPosition.x = 1;
mmi.ptMaxPosition.y = 1;
System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true);
}
}
}
}
[转]c# winform 获取标题栏 状态栏 菜单栏的高度
https://www.360docs.net/doc/4c11404818.html,/blog/237640
MessageBox.Show("当前窗体标题栏高度"+(this.Height - this.ClientRectangle.Height).ToString());//获得当前窗体标题栏高度
ClientRectangle//获取表示控件的工作区的矩形
MessageBox.Show(SystemInformation.PrimaryMonitorSize.ToString()); //获取主显示器屏幕的尺寸(像素)
//获取主显示器当前当前视频模式的尺寸(以象素为单位)
MessageBox.Show("菜单栏高度"+SystemInformation.MenuHeight.ToString()); //获取标准菜单栏的高度
MessageBox.Show("标题栏高度"+SystemInformation.CaptionHeight.ToString()); //获取标准标题栏的高度
MenuHeight//获取一个菜单行的高度(以象素为单位)
CaptionHeight//获取窗口的标准标题栏区域的高度(以象素为单位)
C#程序启动全屏
方法一
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
/*******************************
* 程序启动全屏
* Hewill
* 2009-08-21
******************************/
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public const int HWND_NOTOPMOST= -2;
public const int SWP_SHOWWINDOW=0x0040;
[DllImport("user32.dll")]
private static extern IntPtr FindWindowEx(int hwnd2, int hWnd2, string lpsz1, string lpsz2);
[DllImport("user32.dll")]
private static extern int GetWindowLong (IntPtr hwnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowPos(IntPtr hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
private void Form1_Load(object sender, EventArgs e)
{
IntPtr test = FindWindowEx(0, 0, "Shell_TrayWnd", "");
Console.WriteLine(test.ToString());
int test5 = SetWindowPos(test, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW);
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.Width = Screen.PrimaryScreen.Bounds.Width;
this.Height = Screen.PrimaryScreen.Bounds.Height;
this.Top = 0;
this.Left = 0;
}
}
}
方法二:
private void button1_Click(object sender, EventArgs e)
{
if (this.FormBorderStyle == FormBorderStyle.None)
{
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.WindowState = FormWindowState.Normal;
}
else
{
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
}
****************************************************************
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// 默
认窗体全屏
this.WindowState = FormWindowState.Maximized;
// 去掉窗体标题栏
this.FormBorderStyle = FormBorderStyle.None;
}
}
如果你只想最大化和最小化用
this.MaximizeBox = false;
this.MinimizeBox = false;
*********************************************************
设计窗体,设置Form的WindowState=Maximized
MaximizeBox=false
MiniminzeBox=false
FormBorderStyle = None;
******************************************
哈哈 终于解决了,加入以下几句就可以了。
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
把picturebox的SizeMode属性设为StreatchIamge 再把窗体弄成全屏就行了;设置窗体的BackgroupImageLayout属性为Stretch;在Form_Paint里加入
e.Graphics.DrawImage(Img, this.ClientRectangle);