Page 1 of 1

How to get TreeItem text color

Posted: Fri Mar 24, 2017 4:26 am
by Fent12
I want to get TreeNode text color and backcolor,like node5,
i try like this ,but the object 'box_c' return null

Code: Select all

              string str_temp = "/form[@title='Form1' and @processname='test_tree' and @controltypename='Form1' and @instance='0']/container[@controlname='splitContainer1']/?/?/tree[@controlname='treeView1']//treeitem[@accessiblename='Node5']";

              Ranorex.TreeItem tree_item = null;
              bool aa = Host.Local.TryFindSingle<Ranorex.TreeItem>(str_temp, 5000, out tree_item);
              if (aa)
              {
                  object box_c = tree_item.Element.GetAttributeValue("BackColor"); // return null
                  Color cl = (Color)box_c;
              }
Some body know how to get the node text color and backcolor?

Re: How to get TreeItem text color

Posted: Fri Mar 24, 2017 8:13 am
by odklizec
Hi,

If there is no BackColor attribute available in the Spy, then GetAttributeValue is most probably useless here ;) Try this code instead:

Code: Select all

Color color = tree_item.GetPropertyValue<Color>("BackColor"); 
If the above code fails, you will most probably have to use Invoke Remotely, to get the background color of the problematic element. Check for example this post:
http://www.ranorex.com/forum/get-backgr ... tml#p28331

And this blog post (somewhat old but still valid):
http://www.ranorex.com/blog/transfering ... t-control/

Re: How to get TreeItem text color

Posted: Fri Mar 24, 2017 10:16 am
by Fent12
odklizec,thanks for response

I try to the post you gived,
but when run ,it raise expection " The element does not support the required capability 'control'. "
do you know how to handle this ?

my code like below

Code: Select all

              string str_temp = "/form[@controlname='Form1']/container[@controlname='splitContainer1']/?/?/tree[@controlname='treeView1']//treeitem[@accessiblename='Node5']";
              Ranorex.TreeItem tree_item = null;
              bool aa = Host.Local.TryFindSingle<Ranorex.TreeItem>(str_temp, 5000, out tree_item);
              if (aa)
              {
                    Ranorex.TreeItem tree_item1 = str_temp;
                    Ranorex.Control myCtrl = (Ranorex.Control)tree_item1.Element;  //=>this raise exception
                    //"The element does not support the required capability 'control'."
                  ...

Re: How to get TreeItem text color

Posted: Fri Mar 24, 2017 10:36 am
by odklizec
Why do you use this (failing) line anyway? For obtaining text color from tree item, it should be enough to use tree_item element obtained from TryFindSingle method.

Re: How to get TreeItem text color

Posted: Fri Mar 24, 2017 11:02 am
by Fent12
odklizec,thanks for response

I only want to try the method in post that you gived;

Do you mean that ,the tree item (Node5) text color or back color can get from the var tree_item ?
can you know which API can get it ?

thks

Re: How to get TreeItem text color

Posted: Fri Mar 24, 2017 12:02 pm
by odklizec
I think this code should be enough to obtain the background color of provided tree element?...

Code: Select all

string str_temp = "/form[@controlname='Form1']/container[@controlname='splitContainer1']/?/?/tree[@controlname='treeView1']//treeitem[@accessiblename='Node5']";
              Ranorex.TreeItem tree_item = null;
              bool aa = Host.Local.TryFindSingle<Ranorex.TreeItem>(str_temp, 5000, out tree_item);
              Color color = tree_item.GetPropertyValue<Color>("BackColor"); 

Re: How to get TreeItem text color

Posted: Mon Mar 27, 2017 2:37 am
by Fent12
odklizec wrote:I think this code should be enough to obtain the background color of provided tree element?...

Code: Select all

string str_temp = "/form[@controlname='Form1']/container[@controlname='splitContainer1']/?/?/tree[@controlname='treeView1']//treeitem[@accessiblename='Node5']";
              Ranorex.TreeItem tree_item = null;
              bool aa = Host.Local.TryFindSingle<Ranorex.TreeItem>(str_temp, 5000, out tree_item);
              Color color = tree_item.GetPropertyValue<Color>("BackColor"); 
Thanks for response,
This code confuse me,this code can not complie,"'Ranorex.TreeItem' does not contain a definition for 'GetPropertyValue' "
I read the API document,this method only for the class of 'Ranorex.Control',not for TreeItem
Or my ranorex version lower?
which version do you used?

Re: How to get TreeItem text color

Posted: Mon Mar 27, 2017 7:55 am
by odklizec
Hi,

I'm using latest 6.2.1, however, I've not tried the above code. Simply, I don't have a sample app where I could try it ;) If you can provide such sample app, I may try it. It does not have to be the actual AUT. Just a small sample app with problematic tree control should be enough.

The above code should work. Try to search "GetPropertyValue<Color>" in this forum. It should return multiple posts discussing usage of this method. If the code does not work for you, then I'm afraid, your only hope is Invoke Remotely, as mentioned in another of my posts.

Re: How to get TreeItem text color

Posted: Mon Mar 27, 2017 9:04 am
by Fent12
odklizec wrote:Hi,

I'm using latest 6.2.1, however, I've not tried the above code. Simply, I don't have a sample app where I could try it ;) If you can provide such sample app, I may try it. It does not have to be the actual AUT. Just a small sample app with problematic tree control should be enough.

The above code should work. Try to search "GetPropertyValue<Color>" in this forum. It should return multiple posts discussing usage of this method. If the code does not work for you, then I'm afraid, your only hope is Invoke Remotely, as mentioned in another of my posts.
Thank you very much,
this is my sample app,that i want to get the text color and back color from the 'Node5'

And another, i try the posts that you give ,but find that the TreeItem can not translate to Ranorex.Control,the method GetPropertyValue() only for Ranorex.Control.

Re: How to get TreeItem text color

Posted: Tue Mar 28, 2017 7:34 am
by odklizec
Hi,

Unfortunately, I too was not able to convert the TreeItem into Control and hence neither the GetProperty, nor Invoke Remotely worked for me. I've tried something as described here:
http://www.ranorex.com/forum/get-backgr ... tml#p28331
and here:
http://www.ranorex.com/support/user-gui ... apter.html
But without luck. Maybe someone more knowledgeable in .net and Ranorex will suggest something useful? ;)

Re: How to get TreeItem text color

Posted: Fri Mar 31, 2017 12:28 pm
by Support Team
Hi Fent12,

In order to analyze the issue it would be great if you could provide the VS solution of the sample application (test_tree.exe). I would suggest contacting [email protected] directly including the compressed VS solution.

We look forward to hearing from you.

Sincerely,
Johannes