Reputation: 3509
I've got an issue with a PictureBox
being different sizes between different resolutions.
I have an image which I need to fit into that PictureBox
, but I need to know the drawing size of it since I need to do the resize myself (otherwise the system was just way too slow, and I decided to do the resizing manually, which works fine if I know the resolution needed).
I tried PictureBox.Height / Width
, and PictureBox.ClientRectangle.Height / Width
, but that values are the same for all resolutions. How do I manage to get the actual drawing size?
The initialization code:
//
// 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);
I understand that this has to do with the Anchors being set, but this allows the PictureBox being well seen with different resolutions. How do I grab that real drawing area?
Upvotes: 0
Views: 1200
Reputation: 941237
The ClientSize property tells you how large it is. The ClientSizeChanged event tells you when it changes for any reason, including automatic scaling due to the form's AutoScaleMode property.
Upvotes: 1
Reputation: 36323
I tried PictureBox.Height / Width, and PictureBox.ClientRectangle.Height / Width, but that values are the same for all resolutions.
I think you are looking for dpi settings:
int currentDPI = 0;
using (Graphics g = this.CreateGraphics())
{
currentDPI = (int)g.DpiX;
}
This value should change on computers with different resolution and dpi settings.
Or maybe you are interesting in getting the current screen resolution. They might help:
Rectangle resolution = Screen.PrimaryScreen.Bounds;
Upvotes: 0