C# 删除边框winforms和WindowsState最大化而不全屏显示
我有以下问题,我没有找到解决办法 我想实现一个没有顶栏的Winform,如果可能的话,没有边框。我尝试了几件事都没有成功,下面的几件可以完美地完成这一任务:C# 删除边框winforms和WindowsState最大化而不全屏显示,c#,winforms,C#,Winforms,我有以下问题,我没有找到解决办法 我想实现一个没有顶栏的Winform,如果可能的话,没有边框。我尝试了几件事都没有成功,下面的几件可以完美地完成这一任务: this.Text = string.Empty; this.ControlBox = false; this.FormBorderStyle = FormBorderStyle.SizableToolWindow; 产生以下结果: 小问题是当我或用户触发最大化状态时,因为这将使表单以全屏
this.Text = string.Empty;
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
产生以下结果:
小问题是当我或用户触发最大化状态时,因为这将使表单以全屏模式进入!我不知道如何防止这种情况:
看到了吗?你看不到windows任务栏!我正在使用
WindowState = FormWindowState.Maximized; // Makes a fullscreen that i dont want !
谢谢你的帮助 尝试动态设置大小,它可能会帮助您 不要使用
WindowState=FormWindowState.Maximized代码>
在加载表单时尝试此代码
var rectangle = ScreenRectangle();
Size = new Size(rectangle.Width - 100, rectangle.Height - 100);
Location = new Point(50, 50);
// here 100 is pixel used to reserve from edges,
// you can set lower value according to your requirements
全尺寸
var rectangle = ScreenRectangle();
Size = new Size(rectangle.Width, rectangle.Height);
Location = new Point(0, 0);
屏幕矩形方法为:
public Rectangle ScreenRectangle()
{
return Screen.FromControl(this).Bounds;
}
移去边界
this.FormBorderStyle = FormBorderStyle.None;
我想点击最大化按钮就可以了
// Add following namespaces
using System.Windows.Forms;
using System.Drawing;
// Retrieve the working rectangle from the Screen class using the PrimaryScreen and the
// WorkingArea properties.
Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;
// Set the size of the form slightly less than size of working rectangle.
this.Size = new Size(workingRectangle.Width, workingRectangle.Height);
资料来源:和
GetWorkingArea:获取显示器的工作区域。工作区域是显示器的桌面区域,不包括任务栏、停靠窗口和停靠工具栏。如果要控制窗体最大化,请按以下方式操作:
public class MyForm {
protected override void WndProc(ref Message m) {
const int WM_SYSCOMMAND = 0x0112;
const int SC_MAXIMIZE = 0xF030;
// When form is going to be maximized
if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MAXIMIZE)) {
m.Msg = 0; // <- we don't want a standard maximization
//TODO: tell Windows here what to do when user want to maximize the form
// Just a sample (pseudo maximization)
Location = new Point(0, 0);
Size = new Size(Screen.GetWorkingArea(this).Width,
Screen.GetWorkingArea(this).Height);
}
base.WndProc(ref m);
}
...
}
公共类MyForm{
受保护的覆盖无效WndProc(参考消息m){
const int WM_SYSCOMMAND=0x0112;
const int SC_max=0xF030;
//当形式最大化时
if((m.Msg==WM_SYSCOMMAND)&&(m.WParam.ToInt32()==SC_){
m、 Msg=0;//好吧!多亏了你的回答,我终于用以下两种方法解决了问题
private void MaximizeWindow()
{
var rectangle = Screen.FromControl(this).Bounds;
this.FormBorderStyle = FormBorderStyle.None;
Size = new Size(rectangle.Width, rectangle.Height);
Location = new Point(0, 0);
Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;
this.Size = new Size(workingRectangle.Width, workingRectangle.Height);
}
private void ResizableWindow()
{
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
}
多亏了X-TECH和Luïs,这个问题才得以解决
您好,您只需按照以下两条说明进行操作:
this.MaximumSize=Screen.PrimaryScreen.WorkingArea.Size;
this.WindowState=FormWindowState.Maximized;this.FormBorderStyle=FormBorderStyle.None;
?this.FormBorderStyle=FormBorderStyle.None;//当我触发最大化状态时,仍然以全屏模式显示:\n在某个地方是否有一个窗口设置使任务栏始终位于顶部。如果没有设置,则最大化窗口将始终使用桌面工作区(包括任务栏)。谢谢你的回答,这有助于我进一步了解我在做什么;),我给出了解决这个问题的最终答案,但我会接受你的答案!@Luïs,试着运行代码,这很好,为什么你认为这不起作用?好吧,我已经测试了它,它起作用了。我不知道。对不起,我的错误。你的回答只会让窗口处于一个状态最大化状态,这不是问题所在。
private void MaximizeWindow()
{
var rectangle = Screen.FromControl(this).Bounds;
this.FormBorderStyle = FormBorderStyle.None;
Size = new Size(rectangle.Width, rectangle.Height);
Location = new Point(0, 0);
Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;
this.Size = new Size(workingRectangle.Width, workingRectangle.Height);
}
private void ResizableWindow()
{
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
}