Home > Blockchain >  Incorrect position on elements on Net Windows Forms
Incorrect position on elements on Net Windows Forms

Time:05-05

I am currently working on a resizable Windows Forms app on Visual Studio 2022 using C# and .NET 6.0, and I'm having some trouble with the location of the elements. I'm trying to set the size and position of the elements by multiplying the width and height of the Form by a percentage, like this:

private void Historia_clinica_Load(object sender, EventArgs e)
    {
        panel1.Size = new Size(Width, (int)Math.Floor(Height * 0.05));
        panel1.Left = 0;
        panel1.Top = (int)Math.Floor(Height * 0.95);
    }

The problem is that even though when I print the location of the panel1 it says it is in the correct position, it appears on a completely different place. It should look like this (the blue bar at the bottom)(I positioned it manually): Image

But it looks like this: Image

I don't know if I'm not using correctly the Left, Top and Size properties or if they use different units, I would be grateful for your help.

CodePudding user response:

If you want to fix the panel at the bottom you can refer to the following code:

private void Historia_clinica_Load(object sender, EventArgs e)
{
    panel1.Size = new Size(ClientSize.Width, (int)(ClientSize.Height * 0.05));
    panel1.Dock = DockStyle.Bottom;
}
  • Related