我有一个带有标签控件的表单。在它上面,有标签,组合框和文本框。 在开发机器上,它可以正常工作,但在其他分辨率不同的机器上,控件的位置会发生变化。某处组合框与选项卡控件重叠,某处文本框和标签彼此不对齐。
如何设置它以便我的应用程序无论分辨率如何都能保持形状。
我尝试使用AutoScaleMode进行dpi,继承等但没有任何效果。
由于
答案 0 :(得分:0)
我总是使用布局面板,尤其是TableLayoutPanel。对于包含ComboBox或TextBox的任何行,我将行的高度设置为AutoSize。同样,Label也会进入AutoSize列。您的TabPanel可以跨越多个列。在具有设置大小(绝对或百分比)的列中,将子控件的Anchor设置为Left&填写整栏的权利。
屏幕分辨率不仅会改变事物,还会改变DPI。 DPI是一种Windows设置,可以放大所有控件,在具有精细像素而非厚实像素的显示器上非常有用。使用AutoSize,控件可以自动放大,然后
将此代码复制并粘贴到Form1.Designer.vb中作为示例。记下每个控件的Anchor属性,以及每行和每列的大小设置。
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
Me.Label1 = New System.Windows.Forms.Label()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.TabControl1 = New System.Windows.Forms.TabControl()
Me.TabPage1 = New System.Windows.Forms.TabPage()
Me.TabPage2 = New System.Windows.Forms.TabPage()
Me.TableLayoutPanel1.SuspendLayout()
Me.TabControl1.SuspendLayout()
Me.SuspendLayout()
'
'TableLayoutPanel1
'
Me.TableLayoutPanel1.ColumnCount = 4
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle())
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle())
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
Me.TableLayoutPanel1.Controls.Add(Me.Label1, 0, 0)
Me.TableLayoutPanel1.Controls.Add(Me.ComboBox1, 1, 0)
Me.TableLayoutPanel1.Controls.Add(Me.Label2, 2, 0)
Me.TableLayoutPanel1.Controls.Add(Me.TextBox1, 3, 0)
Me.TableLayoutPanel1.Controls.Add(Me.TabControl1, 0, 1)
Me.TableLayoutPanel1.Location = New System.Drawing.Point(12, 12)
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
Me.TableLayoutPanel1.RowCount = 2
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100.0!))
Me.TableLayoutPanel1.Size = New System.Drawing.Size(260, 238)
Me.TableLayoutPanel1.TabIndex = 0
'
'Label1
'
Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.Right
Me.Label1.AutoSize = True
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 0
Me.Label1.Text = "Label1"
'
'ComboBox1
'
Me.ComboBox1.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.TabIndex = 1
'
'Label2
'
Me.Label2.Anchor = System.Windows.Forms.AnchorStyles.Right
Me.Label2.AutoSize = True
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 2
Me.Label2.Text = "Label2"
'
'TextBox1
'
Me.TextBox1.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 3
'
'TabControl1
'
Me.TabControl1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TableLayoutPanel1.SetColumnSpan(Me.TabControl1, 4)
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.TabIndex = 4
'
'TabPage1
'
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "TabPage1"
Me.TabPage1.UseVisualStyleBackColor = True
'
'TabPage2
'
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "TabPage2"
Me.TabPage2.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 262)
Me.Controls.Add(Me.TableLayoutPanel1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.TableLayoutPanel1.ResumeLayout(False)
Me.TableLayoutPanel1.PerformLayout()
Me.TabControl1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
End Class