0
我有一個帶有選項卡控件的窗體。在它上面,有標籤,組合框和文本框。 在開發機器上,它工作正常,但在其他機器上,分辨率不同,控件的位置發生了變化。某處組合框與選項卡控件重疊,某處文本框和標籤不相互對齊。控件在不同計算機上的位置
如何設置它,使我的應用程序保持形狀,而不管它是什麼分辨率。
我試過AutoScaleMode到dpi,繼承等,但沒有任何工作。
謝謝
我有一個帶有選項卡控件的窗體。在它上面,有標籤,組合框和文本框。 在開發機器上,它工作正常,但在其他機器上,分辨率不同,控件的位置發生了變化。某處組合框與選項卡控件重疊,某處文本框和標籤不相互對齊。控件在不同計算機上的位置
如何設置它,使我的應用程序保持形狀,而不管它是什麼分辨率。
我試過AutoScaleMode到dpi,繼承等,但沒有任何工作。
謝謝
我總是使用佈局面板,特別是TableLayoutPanel。對於包含ComboBox或TextBox的任何行,我將該行的高度設置爲AutoSize。同樣,一個標籤進入AutoSize列。您的TabPanel可以跨越多個列。在設置大小的列(絕對或百分比)中,將子控件的錨設置爲左&填充整列的權限。
不僅屏幕分辨率改變了事情,而且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