我正在创建一个 Windows 窗体应用程序。如何捕获窗口窗体的大小?
目前我的代码中有这样的东西:
PictureBox display = new PictureBox();
display.Width = 360;
display.Height = 290;
this.Controls.Add(display);
display.Image = bmp;
但是,我的显示尺寸被硬编码为特定值。
我知道如果我想绘制一个可以调整大小的正方形,我可以使用这样的方法:
private Rectangle PlotArea;
private int offset = 30;
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
//// Calculate the location and size of the plot area
//// within which we want to draw the graphics:
Rectangle ChartArea = ClientRectangle;
PlotArea = new Rectangle(ChartArea.Location, ChartArea.Size);
PlotArea.Inflate(-offset, -offset);
Draw PlotArea:
g.DrawRectangle(Pens.Black, PlotArea);
}
有没有办法让我使用方法一并获取表单的高度和宽度大小?
我试过下面的代码,但它不起作用...
PictureBox display = new PictureBox();
display.Width = ClientRectangle.Y;
display.Height = ClientRectangle.X;
this.Controls.Add(display);
display.Image = bmp;
最佳答案
获取 Windows 窗体的大小:
int formHeight = this.Height;
int formWidth = this.Width;
关于c# - 获取 Windows 窗体的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7942939/