0

I have defined a form having a GroupBox that contains some Buttons. I have then defined a second mode called "developer mode" that can be entered for certain purpose. For this mode I want to move and change the size of one of the buttons to make space for an other control element (that is only available in this developer mode).

The task seemed to be easy. Simply do this:

Button1.Location = new Point(x1, y1);
Button1.Size = new Size(x2, y2);

The outcomes was, that the buttons got located somewhere totally unpredictable and resized in a different why as expected.

So I tried to find out what the problem is. What I found out is that when I write out the credentials of that button after it got loaded into the form (and before I changed any parameter) it says something different than I have defined inside the properties of Button1. It appears as I defined it in the designer, but its size and location do have different value. E.g.

I defined the Size as 125,35.
The output "Button1.Size.Width" than says 94 and 28 for "Button1.Size.Height".

I define the Location as 495, 280.
The output "Button1.Locaction.X" than says 371 and 228 for "Button1.Location.Y"

Ahm,... so what just happened? Is there any resizing/relocation due to... I don't know... screentype one has? And what ever there is, how can I get control it?

Thanks for any input! Cheers

RadioMan85
  • 337
  • 1
  • 11

1 Answers1

0
  1. Your code sample defines 2 different sizes. Only one can be effective at a certain time. The second one (x3, y3) will overwrite the first one.

  2. Docking affects size and location.

  3. Anchoring affects location and possibly also size.

  4. MinimumSize and MaximumSize of the button may override your manual settings of the size.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • Thx for your response! uups, well the second got added by mistake (for what ever reason) setting up that example, sry. Then docking is disabled, Anchoring shouldn't matter when relocating and resizing and Min Max are set to (0,0) so they shouldn't have any impact either. – RadioMan85 Jun 02 '20 at 04:58