Управление изменением размера в зависимости от разрешения экрана

У меня панель управления. Дополнительные элементы управления находятся на панели. Я установил свойство док-станции для панели как «заполнение». Размер панели изменяется в зависимости от разрешения экрана. но элементы управления остаются прежними. Размер элементов управления на панели не изменяется в зависимости от разрешения экрана.

у меня больше ярлыков, панелей, текстовых полей и кнопок на той же странице.

Как настроить свойство док-станции для изменения размера всех элементов управления на странице в зависимости от разрешения экрана?

Спасибо за любую помощь


person user337173    schedule 10.05.2010    source источник
comment
Свойства Dock и Anchor предназначены только для макета. Свойства AutoScaleMode и AutoScaleDimensions предназначены для изменения разрешения экрана.   -  person AMissico    schedule 10.05.2010


Ответы (3)


Используйте свойство Anchor и привяжите элемент управления ко всем 4 сторонам.

person Hans Olsson    schedule 10.05.2010

Я надеюсь, что это решение (взято из здесь) поможет отобразить все элементы управления внутри формы при изменении разрешения экрана на стороне клиента. :

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); 
person IMMORTAL    schedule 18.02.2013

В дополнение к настройке свойства Dock панели контейнера вам также необходимо установить свойства Anchor или Dock элементов управления в панели. Обычно добавление TableLayoutPanel, FlowLayoutPanel или даже другой панели помогает, когда у вас есть несколько элементов управления в форме.

person AMissico    schedule 10.05.2010