[英]Remove borders winforms and WindowState Maximized without fullscreen
我有以下麻烦,我找不到解决方案。
我想实现一个没有顶栏的Winform,如果可能的话,没有边框。 我尝试了几件事但没有成功,以下是完美的诀窍:
this.Text = string.Empty;
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
产生以下结果:
小问题是当我或用户触发最大化状态时,因为将使表单进入FULLSCREEN模式! 我不知道如何防止这种情况:
看到? 你看不到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;
}
好 ! 感谢您的所有答案,我终于用以下两种方法解决了问题
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,这已经解决了!
如果要控制 表单最大化 ,请执行以下操作:
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);
}
...
}
删除边框
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);
来源: MSDN system.windows.forms.screen.primaryscreen
并删除Windows窗体中的标题栏
嗨,你只能用2条指令来做到这一点:this.MaximumSize = Screen.PrimaryScreen.WorkingArea.Size; this.WindowState = FormWindowState.Maximized;
this.Text = string.Empty;
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
this.Left = this.Top = 0;
this.Height = Screen.GetWorkingArea(this).Height;
this.Width = Screen.GetWorkingArea(this).Width;
GetWorkingArea :获取显示的工作区域。 工作区域是显示器的桌面区域, 不包括任务栏 ,停靠窗口和停靠工具栏。 MSDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.