Set size or location from code/script

Set size or location from code/script

Let’s suppose that we want to change textbox X location in our report from code.

As you probably know most of the units are stored in internal units. And document units only impact on the designer.

If you want to specify X location in centimeters then you need to use convert method. Let’s say we want to set textbox location to 2 centimeters:

PerpetuumSoft.Framework.Drawing.Unit.Convert(2,Unit.Centimeter,Unit.InternalUnit)


Let’s try straightforward solution:

textBox1.Location.X =
  PerpetuumSoft.Framework.Drawing.Unit.Convert(2,Unit.Centimeter,Unit.InternalUnit);


Doesn’t work: Cannot modify Location because it’s not a variable.

It becomes clear when you realize that Location is “Vector” type. And “Vector” is not a class, but structure. Location returns copy of Vector as it is ought to happen for value type variables. From this point we need to use the following code instead:

textBox1.Location = new Vector(
  PerpetuumSoft.Framework.Drawing.Unit.Convert(2,Unit.Centimeter,Unit.InternalUnit),
  textBox1.Location.Y);

Same is true for others properties which have Vector type.






Add Feedback