Edit Rectangle

Hi there,

Is there a way to edit the System.Drawing.Rectangle variable ? For example, I have a variable position1 of type Rectangle. How can I change the value of position1.Left ?

I cannot simply assign position1.Left = 150 which gives Compiler Error.

Thanks.

@Snowman
Rectangle.Left is a get Property:
grafik

As we cannot set it afterwards we can create a new one e.g.
grafik

or we use following static method:
grafik

Hi Peter,

Thanks for your prompt reply.

I tried to assign position1 = position1.Value.Left +80 but it gives the following error:
Compile error(s) encountered processing expression “position1.value.Left + 80”. ‘value’ is not a member of ‘System.Drawing.Rectangle’.

I also tried position1.offset(80,0) but it gives error:
Expression does not produce a value.

Any idea ?

Hi Peter,

Just found a work around. Instead of trying to edit the rectangle, I create and use the new instance with the desire values by: new Rectangle(Left,Top,Width,Depth)

the offset method is a method with no return (void). So it is to be used within an invoke method activity

Oops! It also return error:
‘Rectangle’ does not have a public instance method named ‘offset’ matching the parameter types,…

Probably Offset is a Sub procedure inistead

@Snowman
Methodname is case sensitive. try within Invoke Method activity with upper case O.

Still no luck on it having tried with Capital letter Offset…

It looks like the parameters are not assigned matching the method signature.

for the offset method - Offset(Int32, Int32) it would look like this:

grafik
grafik
grafik

1 Like

Hi Peter,

You are right, I missed those arguments. It gives no error now. But it seems do nothing. May I ask if Offset change the values of rectangle.Left and rectangle.Top ? These two values does not change after the Invoke method.

Offset() should change the position of the rectangle. I believe the reason Offset() doesn’t work with Invoke Method is because Rectangle is a struct instead of a class. Classes are sent by reference while primitive types like struct are sent by value. UiPath sends a copy of your rectangle to Invoke Method. Invoke Method calls Offset() which modifies the copy of your rectangle. You won’t see any difference because Invoke Method was never able to access your original rectangle.

If you just want to change the position of your rectangle, you can modify the X and Y properties instead. (X is for Left and Y is for Top)

image

1 Like

@Snowman
I agree to the statement from @ptrobot
finaly we got it work with the invoke code activity:



grafik

1 Like

Hi Peter, it works, and thanks for all your time checking out the answer.

Dear Peter andptrobot,
I learnt a lot from you both. A brief summary:
To edit the rectangle for further use, can simply edit directly the X, Y, Width, Height. I was caught by using the Top and Left, of which could NOT be edited directly by Assign activity.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.