我遇到以下问题,但我找不到解决方案。
我想实现一个没有顶栏的Winform,如果可能的话,没有边框。我尝试了几件没有成功的事情,以下方法可以完美地完成这个工作:
this.Text = string.Empty;
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.SizableToolWindow;
产生以下结果:
小问题是当我或用户触发最大化状态时,因为会使表单进入FULLSCREEN模式!我不知道如何防止这种情况:
请参阅?你看不到windows任务栏!我正在使用
WindowState = FormWindowState.Maximized; // Makes a fullscreen that i dont want !
感谢您的帮助!
答案 0 :(得分:6)
尝试动态设置大小,它可能对您有帮助。
不要使用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;
}
答案 1 :(得分:6)
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,这已经解决了!
答案 2 :(得分:3)
如果您希望控制而不是表单最大化,请执行以下操作:
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);
}
...
}
答案 3 :(得分:1)
删除边框
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
和Remove the title bar in Windows Forms
功能
答案 4 :(得分:1)
嗨,你只能用2条指令来做到这一点: this.MaximumSize = Screen.PrimaryScreen.WorkingArea.Size; this.WindowState = FormWindowState.Maximized;
答案 5 :(得分:-2)
group_concat
GetWorkingArea :获取显示的工作区域。工作区域是显示器的桌面区域,不包括任务栏,停靠窗口和停靠工具栏。MSDN