【发布时间】:2011-10-30 02:24:39
【问题描述】:
我正在创建一个 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;
【问题讨论】:
标签: c# winforms plot picturebox