我有一个奇怪的问题。当我使用Windows窗体(使用visual basic)时,有时在Designer中对我的窗体布局进行编辑会导致窗体大小和组件布局自行更改。我在这里没有修改任何东西。以下是我正在谈论的一些图像:
我查看了Designer文件,这些是关于一个组件的一些示例差异。
编辑前。
'
'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
编辑后。
'
'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
答案 0 :(得分:1)
当使用两台具有不同DPI的监视器时,通常会发生这种情况。例如,如果您使用笔记本电脑和台式机显示器编辑Windows窗体屏幕并且显示器具有不同的DPI,则会遇到这类问题。
不幸的是,这是一个已知问题,通常最简单的解决方法是确保将您的监视器缩放设置为100%。对于其他解决方法,您可以在此处看到:Why does Visual Studio automatically changes the layout of my form?