sha*_*mim 35 c# desktop-application winforms c#-3.0
我使用C#在VS 2008上工作.以下代码对我不起作用.我的表单设计为1024 x 768分辨率.
我们的客户笔记本电脑是1366 x 768分辨率.为了解决这个问题,我在Form Load事件中设置了以下代码:
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
Run Code Online (Sandbox Code Playgroud)
但是表单没有根据屏幕分辨率调整大小,我的表单底部被隐藏或剪切,或者我错过了滚动条.
有什么方法可以解决这个问题吗?请告诉我语法.提前致谢
ppi*_*icz 32
你不能开始最大化?
将System.Windows.Forms.Form.WindowState属性设置为FormWindowState.Maximized
Oli*_*bes 19
如果要以编程方式设置表单大小,请将表单的StartPosition属性设置为Manual.否则表单自己的定位和大小调整算法会干扰您的.这就是您遇到问题中提到的问题的原因.
示例:以下是我将表单大小调整为原始大小和屏幕工作区大小之间的大小.我还将表格放在工作区域中:
public MainView()
{
InitializeComponent();
// StartPosition was set to FormStartPosition.Manual in the properties window.
Rectangle screen = Screen.PrimaryScreen.WorkingArea;
int w = Width >= screen.Width ? screen.Width : (screen.Width + Width) / 2;
int h = Height >= screen.Height ? screen.Height : (screen.Height + Height) / 2;
this.Location = new Point((screen.Width - w) / 2, (screen.Height - h) / 2);
this.Size = new Size(w, h);
}
Run Code Online (Sandbox Code Playgroud)
请注意,设置WindowState到FormWindowState.Maximized本身并不改变恢复窗口的大小.因此,只要窗口最大化,窗口可能看起来很好,但是在恢复时,窗口大小和位置仍然可能是错误的.因此,即使您打算以最大化方式打开窗口,我也建议您设置大小和位置.
Yok*_*nna 10
可能是最大化的表单有帮助,或者您可以在表单加载时手动执行此操作:
代码块
this.Location = new Point(0, 0);
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
Run Code Online (Sandbox Code Playgroud)
然后,使用锚定,因此表单内的子控件会自动适合您表单的新大小.
希望这可以帮助,
将form属性设置为以最大化状态打开.
this.WindowState = FormWindowState.Maximized;
Run Code Online (Sandbox Code Playgroud)
小智 6
int h = Screen.PrimaryScreen.WorkingArea.Height;
int w = Screen.PrimaryScreen.WorkingArea.Width;
this.ClientSize = new Size(w , h);
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以简单地设置窗口状态
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
Run Code Online (Sandbox Code Playgroud)