EzText

EzText is a collection of many properties that can be used to glean information about text within the application. Using this functionality is somewhat complicated so be sure to check out the Samples and Usage section at the bottom

Syntax

        public class EzText : EzElement

Constructors

Name Input Description
EzText(EzElement element) EzElement Creates a new instance of EzText based on an existing EzElement
EzText(EzRoot root) EzRoot Creates a new instance of EzText based on an existing EzRoot
EzText(AutomationElement element) AutomationElement Creates a new instance of EzText based on an existing AutomationElement

Properties

Name Type Description
TextPattern TextPattern Houses the underlying windows TextPattern. Will return null if ExposeBackingWindowsPatterns is not set to true
AlwaysReset bool Houses the underlying value of Config.AlwaysResetEzText. If this is true, then Reset() will never need to be called; all properties are re-evaluated on each access. If it is false, then Reset() needs to be called to refresh element. Default is false
FontName EzTextResult<string> Gets the font name of the current EzElement
FontSize EzTextResult<double> Gets the font size of the current EzElement
FontWeight EzTextResult<int> Gets the font weight of the current EzElement
BackgroundColor EzTextResult<int> Gets the background color of the current EzElement
ForegroundColor EzTextResult<int> Gets the foreground color of the current EzElement
HorizontalAlignment EzTextResult<HorizontalTextAlignment> Gets the horizontal text alignment of the current EzElement
IsHidden EzTextResult<bool> Determines whether or not the element is currently hidden
IsReadOnly EzTextResult<bool> Determines whether or not the element is read-only
IsItalic EzTextResult<bool> Determines whether or not the element is in italics
IsSubscript EzTextResult<bool> Determines whether or not the element is subscript
FirstLineIndentation EzTextResult<double> Determines the first line indentation of the current EzElement
IndentationLeading EzTextResult<double> Determines the leading indentation of the current EzElement
IndentationTrailing EzTextResult<double> Determines the trailing indentation of the current EzElement
MarginTop EzTextResult<double> Determines the top margin of the eurrent EzElement
MarginBottom EzTextResult<double> Determines the bottom margin of the current EzElement
OutlineSytle EzTextResult<OutlineStyle> Determines the outline style of the current EzElement
OverlineColor EzTextResult<int> Determines the overline color of the current EzElement
OverlineStyle EzTextResult<OverlineStyle> Determines the overline style of the current EzElement
StrikethroughColor EzTextResult<int> Determines the strikethrough color of the current EzElement
StrikethroughStyle EzTextResult<TextDecorationLineStyle> Determines the strikethrough style of the current EzElement
UnderlineColor EzTextResult<int> Determines the underline color of the current EzElement
UnderlineStyle EzTextResult<TextDecorationLineStyle> Determines the underline style of the current EzElement
TabStops EzTextResult<double[]> Determines the tab stops of the current EzElement
TextFlowDirection EzTextResult<FlowDirections> Determines the text flow direction of the current EzElement

Methods

Name Return Type Description
GetTextValue(int maxLength = -1) string Gets the current value of the text contained within the EzElement. maxLength variable determines how much of the text should be returned. -1 implies that all of the text should be returned
Reset() void Resets the underlying value of all text properties. This is used if the element may have changed. Note that if config setting AlwaysResetEzText is set to true (which it is by default), this method does not need to be called; all properties are re-checked on each access event

Samples and Usage

The main purpose of this class is to be able to get information about any text that is housed within the EzElement sitting underneath. Each property can be accessed via the created instance of EzText. From there, you can use the return value to determine information about the property you are querying for. Each property returns an instance of EzTextResult<T>. See sample usage below in which we determine the font name of an EzTextElement:

        //Simple method to launch Windows' built in calculator application
        const string calculatorPath = C:\\Windows\\System32\\calc.exe";

        //Get an instance of EzProcess in order to create EzRoot.  Wrap it in a using statement to ensure that
        //.Dispose() is called
        using (EzProcess process = new EzProcess(calculatorPath, "Calculator"))
        {
            process.StartProcess();

            //Get the root element of the application
            EzRoot root = new EzRoot(process);

            //First, get the element that you want.  We are querying all children of the root element for an element
            //whose AutomationId property is "TestAutomationId"
            EzElement element = root.RootElement.FindChildByAutomationId("TestAutomationId");

            //Next, use the element that we found to create an instance of EzText (provided of course that "element"'s
            //ControlType is Text)
            EzText textElement = new EzText(element);

            //Next, call the .HandleResult method on the instance of EzTextResult<T> where T in this case is a string
            textElement.FontName.HandleResult(() =>
            {
                //The first delegate method is called if the action is unsupported
                Console.WriteLine("This action was unsupported!  Font name could not be determined");
            }, () =>
            {
                //The second delegate is called if the result is mixed meaning that a definitive value cannot be
                //determined
                Console.WriteLine(The result was mixed.  In this case it means that the element had more than one font");
            }, res =>
            {
                //The final delegate is called if the result can be definitively determined.  This delegate will take
                //an input of type T where T, in this case, is a string.  We can use that string value to do
                //verification, or for this example, just log the results
                Console.WriteLine(Font name for current EzElement: " + res);
            });
        }