Modify aplication's control property by user code

Class library usage, coding and language questions.
mczyzewski
Posts: 2
Joined: Tue Jan 09, 2018 11:35 am

Modify aplication's control property by user code

Post by mczyzewski » Tue Jan 09, 2018 11:58 am

Hi,
is it possible to modify aplication's control property by user code, for example change visibility or caption of button?
When I tried change button's text, I received error:
"Property or indexer 'Button.Text' cannot be assigned to -- it is read only (...)"

Best regards :-)
Marek

User avatar
N612
Posts: 62
Joined: Mon Jul 11, 2016 4:01 pm

Re: Modify aplication's control property by user code

Post by N612 » Thu Jan 11, 2018 10:03 pm

Typically most applications are going to protect against other applications trying to change them as changing something may break it or cause you to access things you should not. While it is possible, there is no easy way to do it as far as I know. If you can provide more information about what you are trying to achieve, we may be able to provide another way.

mczyzewski
Posts: 2
Joined: Tue Jan 09, 2018 11:35 am

Re: Modify aplication's control property by user code

Post by mczyzewski » Fri Jan 12, 2018 2:57 pm

I do not need to change the properties of the controls, I only asked if there is such a possibility.

ahoisl
Certified Professional
Certified Professional
Posts: 125
Joined: Fri Sep 07, 2007 8:16 am

Re: Modify aplication's control property by user code

Post by ahoisl » Sun Jan 14, 2018 7:48 pm

Actually, this is possible for a lot of properties/attributes. Which properties can be set, depends on the technology (WPF, WinForms, Web, ...) and the property itself.

You can easily try it out by switching to the "Advanced" tab in Ranorex Spy. This tab will also show control specific properties for most technologies (WPF, WinForms, Java, ...) and also provides the possibility to set the properties shown in bold. Note that some bold properties may not be settable if the type is a complex type (e.g. does not allow serialization) or the control just does not let it being set - but give it a try.

If it works in Spy, then you can use the Element.SetAttributeValue method to perform the same in code.

Regards,
Alex
Ranorex Team