0

I have a strange issue. When I am working with Windows Forms (using visual basic) sometimes edits to my Form Layout in Designer causes the Form size and Component layout to change on it's own. I'm not modifying anything myself here. Here are some images of what I'm talking about:

Before Edit

After Edit

I have looked at the Designer file and these are some sample diffs concerning one component.

Before Edit.

    '
    'btnStop
    '
    Me.btnStop.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.btnStop.BackColor = System.Drawing.Color.Red
    Me.btnStop.Enabled = False
    Me.btnStop.Font = New System.Drawing.Font("Microsoft Sans Serif", 60.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnStop.ForeColor = System.Drawing.SystemColors.Control
    Me.btnStop.Location = New System.Drawing.Point(546, 398)
    Me.btnStop.Name = "btnStop"
    Me.btnStop.Size = New System.Drawing.Size(450, 250)
    Me.btnStop.TabIndex = 5
    Me.btnStop.Text = "Stop"
    Me.btnStop.UseVisualStyleBackColor = False

After Edit.

    '
    'btnStop
    '
    Me.btnStop.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.btnStop.BackColor = System.Drawing.Color.Red
    Me.btnStop.Enabled = False
    Me.btnStop.Font = New System.Drawing.Font("Microsoft Sans Serif", 60.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnStop.ForeColor = System.Drawing.SystemColors.Control
    Me.btnStop.Location = New System.Drawing.Point(1092, 765)
    Me.btnStop.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
    Me.btnStop.Name = "btnStop"
    Me.btnStop.Size = New System.Drawing.Size(900, 481)
    Me.btnStop.TabIndex = 5
    Me.btnStop.Text = "Stop"
    Me.btnStop.UseVisualStyleBackColor = False
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
r3dfarce
  • 161
  • 1
  • 2
  • 9
  • First thing I'd check is your Form's AutoScaleMode. Try changing and see if you get any differences. AutoScaleMode None > Font > Dpi > Inherit – video.baba Apr 05 '18 at 03:23

1 Answers1

1

This usually happens when two monitors with different DPIs are used. So for example, if you use your laptop and a desktop monitor to edit your Windows Forms screens and the displays have different DPI, you encounter these kind of issues.

It's unfortunately a known issue and usually the easiest way to fix it is to make sure that your monitor scaling is set to 100%. For other workaround you can see here: Why does Visual Studio automatically changes the layout of my form?

Mikael Koskinen
  • 12,306
  • 5
  • 48
  • 63
  • That was my issue. Using 1080p monitors at office then using my Surface Book when away. I did find that changing the resolution / DPI for your system works only if you change it then logout or reboot. – r3dfarce Apr 18 '18 at 19:24