2011-07-01 1 views
0

J'ai un formulaire avec un onglet. Au-dessus, il y a des lables, des combos et des zones de texte. Sur la machine de développement, cela fonctionne très bien mais sur d'autres machines, où la résolution est différente, la position des contrôles est modifiée. La zone de liste déroulante Somewhere chevauche le contrôle onglet, les zones de texte et les listes ne sont pas alignées les unes avec les autres.Position des contrôles sur différents ordinateurs

Comment le définir pour que mon application conserve la forme quelle que soit sa résolution.

J'ai essayé AutoScaleMode en dpi, hérité etc. mais rien n'a fonctionné.

Merci

Répondre

0

J'utilise toujours des panneaux de mise en page, en particulier les TableLayoutPanel. Pour toute ligne qui contient un contrôle ComboBox ou TextBox, j'ai défini la hauteur de la ligne sur AutoSize. De même, une étiquette va dans une colonne AutoSize. Votre TabPanel peut s'étendre sur plusieurs colonnes. Dans les colonnes avec des tailles définies (absolu ou pourcentage), définissez l'ancre du contrôle enfant sur & droite pour remplir la colonne entière.

Non seulement la résolution de l'écran change les choses, mais le DPI. DPI est un paramètre Windows qui agrandit tous les contrôles, utile sur les moniteurs avec des pixels fins plutôt que des pixels volumineux. Avec AutoSize, les contrôles peuvent agrandir automatiquement, puis

Copiez et collez ce code dans Form1.Designer.vb pour un exemple. Prenez note de la propriété Anchor de chaque contrôle et des paramètres de taille pour chaque ligne et colonne.

<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 
Questions connexes