c# - 获取 Windows 窗体的大小

标签 c# winforms plot picturebox

我正在创建一个 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/

相关文章:

c# - 在 C# 中将 At 命令的结果发送到 USB 调制解调器并读取结果

c# - 使用 Excel Interop 的 set_Value(XLRangeValueDataType.XLRangeValueMSPersistXML,object) 时出错

c# - 使用本地化枚举作为数据源

c# - 始终选中一行的 DataGridView

python - 在 Python 中使用 numpy 和 scipy 在 matplotlib 中制作分箱箱线图

r - 绘制每毫秒的时间序列

c# - 表格字符编码 - 应用程序异常

c# - json.net 处理不存在的 token

c# - 自动滚动面板到底部

r - R 中的森林图 - 文本高度错误 TRUE/FALSE