Big*_*Bug 6 c# plot picturebox winforms
我正在创建一个Windows窗体应用程序.如何捕获窗体的大小?
目前我的代码中有一些看起来像这样的东西:
PictureBox display = new PictureBox();
display.Width = 360;
display.Height = 290;
this.Controls.Add(display);
display.Image = bmp;
Run Code Online (Sandbox Code Playgroud)
但是,我的显示器的大小硬编码为特定值.
我知道如果我想绘制一个重新调整尺寸的正方形,我可以使用这样的东西:
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);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让我使用方法一并获取高度和宽度的表单大小?
我已经尝试了以下代码,但它不起作用......
PictureBox display = new PictureBox();
display.Width = ClientRectangle.Y;
display.Height = ClientRectangle.X;
this.Controls.Add(display);
display.Image = bmp;
Run Code Online (Sandbox Code Playgroud)
T30*_*T30 12
为了获得一个Windows窗体的大小:
int formHeight = this.Height;
int formWidth = this.Width;
Run Code Online (Sandbox Code Playgroud)
PictureBox display = new PictureBox();
display.Width = ClientRectangle.Width;
display.Height = ClientRectangle.Height;
this.Controls.Add(display);
display.Image = bmp;
Run Code Online (Sandbox Code Playgroud)
调整窗口大小时:
private void Form1_Resize(object sender, System.EventArgs e)
{
Control control = (Control)sender;
// set the PictureBox width and heigh here using control.Size.Height
// and control.Size.Width
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60216 次 |
| 最近记录: |