T
T
TomYol2020-11-20 16:46:37
C++ / C#
TomYol, 2020-11-20 16:46:37

Why does the element change its location at different screen diagonals?

On the form I create GroupBox, in it some elements. On my monitor (1080p) everything is displayed as it should. Threw off a friend, he has a laptop (also 1080p). There, the groupbox appears at the wrong point, although the resolution is the same, the laptop only has a smaller diagonal. I'll create the groupbox like this:

//groupbox
            DescriptBox.AutoSize = true;
            DescriptBox.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            DescriptBox.BackColor = SystemColors.InactiveCaption;
            DescriptBox.Location = new Point(0, 801);
            DescriptBox.Name = "DescriptBox";
            DescriptBox.Size = new Size(280, 220);
            DescriptBox.Parent = pictureBox1;
            DescriptBox.BringToFront();
            pictureBox1.Controls.Add(DescriptBox);
 
            //textbox1
            CountryName.BackColor = SystemColors.InactiveCaption;
            CountryName.BorderStyle = BorderStyle.None;
            CountryName.Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)));
            CountryName.Location = new Point(6, 19);
            CountryName.Multiline = true;
            CountryName.Name = "CountryName";
            CountryName.Size = new Size(147, 65);
            DescriptBox.Controls.Add(CountryName);
 
            //picturebox
            FlagIcon.Location = new Point(144, 19);
            FlagIcon.Name = "FlagIcon";
            FlagIcon.Size = new Size(123, 68);
            DescriptBox.Controls.Add(FlagIcon);
 
            //texbox2
            CountryDescript.BackColor = SystemColors.InactiveCaption;
            CountryDescript.BorderStyle = BorderStyle.None;
            CountryDescript.Font = new Font("Microsoft YaHei", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(204)));
            CountryDescript.Location = new Point(0, 93);
            CountryDescript.Multiline = true;
            CountryDescript.Name = "CountryDescript";
            CountryDescript.ScrollBars = ScrollBars.Vertical;
            CountryDescript.Size = new Size(273, 126);
            DescriptBox.Controls.Add(CountryDescript);

How it should be displayed (groupox in the lower left corner):
5fb7c8538a8a3526974942.jpeg

How it should be displayed (groupox in the lower left corner):
5fb7c882e7077154458267.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Shporsoft, 2020-11-20
@Shporsoft

I will say right away - I worked in C #, but with Windows Forms, not very long. I think you should just think about the adaptive design of the program.
Here's an explanation, I'll tell you on the example of web design:
There is a phone, it has a resolution of 1024 * 600 pixels. And take a laptop, it also has a resolution of 1024 * 600 pixels. But the site looks completely different on a laptop, and completely different on a phone.
In the case of Windows Forms, I've seen how the anchor property is applied to elements like yours.
Screen size matters.

I
itgood, 2020-11-20
@itgood

everything is simple in winforms, the canvas container is used, binding to coordinates is in progress

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question