2010-05-10 3 views
2

J'ai un contrôle de panneau. Plus de contrôles sont dans le panneau. J'ai défini la propriété dock pour le panneau comme 'fill'. Le panneau est redimensionné en fonction de la résolution de l'écran. mais les contrôles restent les mêmes. Les contrôles dans le panneau ne sont pas redimensionnés en fonction de la solution d'écran.Contrôle le redimensionnement en fonction de la résolution de l'écran

J'ai plus d'étiquettes et de panneaux et de zones de texte et de bouton dans la même page.

Comment définir la propriété Dock pour redimensionner tous les contrôles de la page en fonction de la résolution de l'écran?

Merci pour toute aide

+1

Dock et les propriétés d'ancrage sont pour « mise en page » seulement. Les propriétés AutoScaleMode et AutoScaleDimensions sont destinées aux modifications de "résolution d'écran". – AMissico

Répondre

1

Utilisez la propriété Anchor et ancrer le contrôle à tous les 4 côtés.

0

En plus de définir la propriété Dock du conteneur Panel, vous devez également définir les propriétés Anchor ou Dock des contrôles dans le Panel. Habituellement, ajouter un TableLayoutPanel, un FlowLayoutPanel, ou même un autre Panel vous aidera lorsque vous aurez plusieurs contrôles sur un Formulaire.

1

J'espère que cette solution (tirée de here) contribuera à afficher tous les contrôles à l'intérieur du formulaire lorsque la résolution change d'écran du côté client:

int i_StandardHeight = 768;//Developer Desktop Height Where the Form is Designed 
       int i_StandardWidth = 1024; ;//Developer Desktop Width Where the Form is Designed 
       int i_PresentHeight = Screen.PrimaryScreen.Bounds.Height; 
       int i_PresentWidth = Screen.PrimaryScreen.Bounds.Width; 
       float f_HeightRatio = new float(); 
       float f_WidthRatio = new float(); 
       f_HeightRatio = (float)((float)i_PresentHeight/(float)i_StandardHeight); 
       f_WidthRatio = (float)((float)i_PresentWidth/(float)i_StandardWidth); 
       foreach (Control c in this.Controls) 
       { 
        if (c.GetType().ToString() == "System.Windows.Forms.Button") 
        { 
         Button obtn = (Button)c; 
         obtn.TextAlign = ContentAlignment.MiddleCenter; 
        } 
        if (c.HasChildren) 
        { 
         foreach (Control cChildren in c.Controls) 
         { 
          cChildren.SetBounds(Convert.ToInt32(cChildren.Bounds.X * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Y * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Width * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Height * f_HeightRatio)); 
          //cChildren.Font = new Font(cChildren.Font.FontFamily, cChildren.Font.Size * f_HeightRatio, cChildren.Font.Style, cChildren.Font.Unit, ((byte)(0))); 
         } 
         c.SetBounds(Convert.ToInt32(c.Bounds.X * f_WidthRatio), Convert.ToInt32(c.Bounds.Y * f_WidthRatio), Convert.ToInt32(c.Bounds.Width * f_WidthRatio), Convert.ToInt32(c.Bounds.Height * f_HeightRatio)); 
         // c.Font = new Font(c.Font.FontFamily, c.Font.Size * f_HeightRatio, c.Font.Style, c.Font.Unit, ((byte)(0))); 
        } 
        else 
        { 
         c.SetBounds(Convert.ToInt32(c.Bounds.X * f_WidthRatio), Convert.ToInt32(c.Bounds.Y * f_WidthRatio), Convert.ToInt32(c.Bounds.Width * f_WidthRatio), Convert.ToInt32(c.Bounds.Height * f_HeightRatio)); 
         // c.Font = new Font(c.Font.FontFamily, c.Font.Size * f_HeightRatio, c.Font.Style, c.Font.Unit, ((byte)(0))); 
        } 
       } 
       this.Height = Convert.ToInt32(i_StandardHeight * f_HeightRatio); 
       this.Width = Convert.ToInt32(i_StandardWidth * f_WidthRatio); 
+0

merci son travail –

Questions connexes