0

Just for testing I have created a new windows forms project with a picturebox on the form and changed the size of it to 100x100. This is the InitializeComponents function:

private void InitializeComponent()
{
    this.pictureBox1 = new System.Windows.Forms.PictureBox();
    ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
    this.SuspendLayout();
    // 
    // pictureBox1
    // 
    this.pictureBox1.Location = new System.Drawing.Point(13, 13);
    this.pictureBox1.Name = "pictureBox1";
    this.pictureBox1.Size = new System.Drawing.Size(100, 100);
    this.pictureBox1.TabIndex = 0;
    this.pictureBox1.TabStop = false;
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(800, 450);
    this.Controls.Add(this.pictureBox1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
    this.ResumeLayout(false);

}

This is my From1_Load function:

private void Form1_Load(object sender, EventArgs e)
{
    MessageBox.Show(pictureBox1.Size.ToString());
}

And this is what I get when I run the app:

enter image description here

Why do I get width=67 height= 65 when it is clear in init that it was meant to be 100x100? My monitor res is 3840x2160 with change of size of text as 125% Tweaking these settings do not change the result.

Raul Junc
  • 35
  • 5
  • [How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?](https://stackoverflow.com/a/13228495/7444103). – Jimi Aug 24 '19 at 16:21
  • I found Vasco's answer in the link to be a simple solution that worked for me. – TaW Aug 24 '19 at 16:58
  • @TaW When moving to full-scale DPIAware, `=> AutoScaleMode = Dpi` and each control's Font must be assigned explicitly, since some controls inherits it and some don't. If one keeps `AutoScaleMode = Font` and doesn't set the Fonts, weird things happen. Someone thinks that keeping autoscale to Font means less work in adjusting the interface of a previously DPI unaware app. That's a nice thought. Doesn't happen, though. After a while (and a lot of patches), the TLP/FLP controls will grow on you. – Jimi Aug 24 '19 at 17:38

1 Answers1

0

Add an image reference.

pictureBox1.Image = Properties.Resources.myImage;

See what happens then, I just need more information to help...

rom_totach
  • 106
  • 8