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:


Let’s try straightforward solution:

textBox1.Location.X =

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(

Same is true for others properties which have Vector type.

Add Feedback