我有以下麻烦,我找不到解决方案.
我想实现一个没有顶栏的Winform,如果可能的话,没有边框.我尝试了几件事但没有成功,以下是完美的诀窍:
this.Text = string.Empty;
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
Run Code Online (Sandbox Code Playgroud)
产生以下结果:
小问题是当我或用户触发最大化状态时,因为将使表单进入FULLSCREEN模式!我不知道如何防止这种情况:
看到?你看不到windows任务栏!我正在使用
WindowState = FormWindowState.Maximized; // Makes a fullscreen that i dont want !
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助 !
好 !感谢您的所有答案,我终于用以下两种方法解决了问题
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;
}
Run Code Online (Sandbox Code Playgroud)
感谢X-TECH和Luïs,这已经解决了!
试试这个动态设置大小,它可能会帮助你.
不要使用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
Run Code Online (Sandbox Code Playgroud)
全尺寸
var rectangle = ScreenRectangle();
Size = new Size(rectangle.Width, rectangle.Height);
Location = new Point(0, 0);
Run Code Online (Sandbox Code Playgroud)
屏幕矩形方法是:
public Rectangle ScreenRectangle()
{
return Screen.FromControl(this).Bounds;
}
Run Code Online (Sandbox Code Playgroud)