0

我遇到了PictureBox不同分辨率之间大小不同的问题。

我有一个需要适应的图像PictureBox,但我需要知道它的绘图大小,因为我需要自己调整大小(否则系统太慢了,我决定手动调整大小,这如果我知道所需的分辨率,效果很好)。

我试过PictureBox.Height / WidthPictureBox.ClientRectangle.Height / Width,但所有分辨率的值都是相同的。我如何设法获得实际的图纸尺寸?

初始化代码:

            // 
            // PicboxRed
            // 
            this.PicboxRed.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));

            this.PicboxRed.BackColor = System.Drawing.Color.DimGray;
            this.PicboxRed.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
            this.PicboxRed.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PicboxRed.Location = new System.Drawing.Point(19, 92);
            this.PicboxRed.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
            this.PicboxRed.Name = "PicboxRed";
            this.PicboxRed.Size = new System.Drawing.Size(852, 840);
            this.PicboxRed.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal;
            this.PicboxRed.TabIndex = 9;
            this.PicboxRed.TabStop = false;
            this.PicboxRed.Click += new System.EventHandler(this.PicboxRed_Click);
            this.PicboxRed.Paint += new System.Windows.Forms.PaintEventHandler(this.Picbox_Paint);

我知道这与设置的锚点有关,但这可以让 PictureBox 在不同的分辨率下被很好地看到。我如何抓住那个真正的绘图区域?

4

2 回答 2

1

ClientSize 属性告诉您它有多大。ClientSizeChanged 事件会告诉您它何时因任何原因而更改,包括由于表单的 AutoScaleMode 属性而自动缩放。

于 2012-09-06T18:10:39.193 回答
0

I tried PictureBox.Height / Width, and PictureBox.ClientRectangle.Height / Width, but that values are the same for all resolutions.

我认为您正在寻找 dpi 设置:

int currentDPI = 0;

using (Graphics g = this.CreateGraphics())
{
    currentDPI = (int)g.DpiX;    
}

此值应在具有不同分辨率和 dpi 设置的计算机上更改。

或者,也许您对获取当前屏幕分辨率感兴趣。他们可能会帮助:

Rectangle resolution = Screen.PrimaryScreen.Bounds;

于 2012-09-06T16:39:54.227 回答