Forum Discussion

kumar_perlaa's avatar
12 years ago

How to find background colour of Text Box of Edit Control ?


Kindly suggest a sol for above query?

Below is the scenario( Refer comment lines please)

  1. Enter the value in Text box.

  2. Text box Background colour is changing  into Green colour.

Code Snippet

function GetBackGroundColour()


  var ULEditBoxObj    = getBackgroundColour();// Object reference

  var ULEditBoxObj1   = ULEditBoxObj.WinFormsObject("TextBoxMaskBox", "");// Text box(TB) Object Reference.


  var ULValue         = ULEditBoxObj1.wText;  // Existing value from TB($87.76)

  Log.Message("Existing U/L value-->:" + ULValue);

  var ULValue         = aqConvert.StrToInt(ULValue);

  var ULValue         = ULValue + 1;

  Log.Message("U/L New Value-->:" +ULValue);

  ULEditBoxObj1.SetText(ULValue);// Text box background colour changing to Green colour.... and Apply button is enabling on the window.




What is the method I need to call to handle background colour ? Is it get_BackColor() , get_BackColorBrush() or some other methods, Please let me know?

5 Replies

  • Hi Kumar,

    first, I don't understand what you get with this function:

    var ULEditBoxObj = getBackGrounddColorObj();

    Is this function get the Parent Object of the textBox of interest ? If  Yes, I guess the name is not appropriate.

    second, you don't have to go under the BackColor Properties to get the BackColor of the textBox.

    var ULColor = ULEditBoxObj1.BackColor;

    By going below, you go to get the static DarkGreen color. as,  I'm not sure you can get the DarkGreenColor with this:

    var color = BuiltIn.clGreen;// Green color value(255)

    I will use

    var darkGreenColor == ULColor.DarkGreen ;

    to get the static DarkGreen color (it is may be not the most elegant solution).

    Finnaly, at this step I'm not sure you can use. 

    if (darkGreenColor == ULColor)

    I guess you need to use the native Equals method

    if (darkGreenColor.Equals(ULColor))


  • Hi Kumar,

    Most of the properties defines by the .NET framework are available on the object you get by the WinfFormsObject method (ie the ULEditBoxObj1 text box).  All Properties available for Test Complete may be seen using the ObjectSpy in the Advanced view. The one that will be of interest for you should be BackColor.

    TheBackGroundColor = ULEditBoxObj1.Color;

  • Thanks for the reply. I have followed your intructions,but I am unable to capture the background color of textbox.

    Here is the new code:

    function BackGroundColor()


    var ULEditBoxObj = getBackGrounddColorObj();

    var ULEditBoxObj1 = ULEditBoxObj.WinFormsObject("TextBoxMaskBox", "");

    var ULValue = ULEditBoxObj1.wText; // Existing Value of TB

    var ULValue = aqConvert.VarToStr(ULValue +1)

    Log.Message("U/L New Value-->:" +ULValue);



    var color = BuiltIn.clGreen;// Green color value(255)

    var ULColor = ULEditBoxObj1.BackColor.DarkGreen.get_DarkGreen();

    // var ULColor = aqConvert.VarToInt(ULColor); -->No use of this StMT. Getting error msg here also

    if(ULColor == color) //Error MSG-->Object Does not support this proerty/method


    Log.Message("Green Color");




    Log.Message("Color is not green");





  • Thansks for the reply.

    Pre requiste conditions:

    1. Above method and Rename it has Function TextBox()

     2. Invoke GetBackgroundColor () in Function TextBox()

    Below is the source code snippet for finding the background color of the button/Text etc...

    At present the   below method checks whether the color is "Green" Or not.? Simillary we can implement the same logic  for the other colors like "Orange","Blue" that case we need to use Switch(Color) case:


    /* Function: GetBackgroundColor

    Desc: Gets the background color for the control.

    Input: None

    Return: biSColorChanged

    Status: final

    Date: 17 Jan 2013


    function GetBackgroundColor()


    biSColorChanged = false;

    var ULColor = ULEditBoxObj1.BackColor;

    var ULRed = ULColor.get_R(); // R-->0

    var ULGreen = ULColor.get_G();//G-->204

    var ULBlue = ULColor.get_B();//B-->0 ; HEX-> #00CC00

    var ULRGBValue1 = aqString.Concat(ULRed,ULGreen);

    var ULRGBValue2 = aqString.Concat(ULRGBValue1,ULBlue);

    if(ULRGBValue2 == Project.Variables.RGB)


    Log.Message("Underlying Textbox Background color is changed to Green:");

    biSColorChanged = true;




    Log.Warning("Underlying Textbox Background color is NOT changed to Green:")



    return biSColorChanged;




  • Correction in Above post:

    Pre requiste conditions:

    1. Rename above method  has Function TextBox()

     2. Invoke GetBackgroundColor () in "Function TextBox()"

      example: Function TextBox() { ....

    GetBackgroundColor ()