TransformPattern.Resize Method

Resizes the control.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public void Resize(
	double width,
	double height
)

Parameters

width
Type: System.Double

The new width of the window, in pixels.

height
Type: System.Double

The new height of the window, in pixels.

ExceptionCondition
InvalidOperationException

The CanResize property is false.

When called on a control that supports split panes, this method can have the side effect of resizing other contiguous panes.

An object cannot be moved, resized, or rotated such that its resulting screen location would be completely outside the coordinates of its container and inaccessible to keyboard or mouse. For example, when a top-level window is moved completely off-screen or a child object is moved outside the boundaries of the container's viewport. In these cases the object is placed as close to the requested screen coordinates as possible with the top or left coordinates overridden to be within the container boundaries.

In the following example, a TransformPattern control pattern is obtained from an AutomationElement and subsequently used to resize the AutomationElement.

///-------------------------------------------------------------------- 
/// <summary> 
/// Obtains a TransformPattern control pattern from  
/// an automation element. 
/// </summary> 
/// <param name="targetControl">
/// The automation element of interest. 
/// </param> 
/// <returns> 
/// A TransformPattern object. 
/// </returns> 
///-------------------------------------------------------------------- 
private TransformPattern GetTransformPattern(
    AutomationElement targetControl)
{
    TransformPattern transformPattern = null;

    try
    {
        transformPattern =
            targetControl.GetCurrentPattern(TransformPattern.Pattern)
            as TransformPattern;
    }
    catch (InvalidOperationException)
    {
        // object doesn't support the TransformPattern control pattern 
        return null;
    }

    return transformPattern;
}


...


///-------------------------------------------------------------------- 
/// <summary> 
/// Calls the TransformPattern.Resize() method for an associated  
/// automation element. 
/// </summary> 
/// <param name="transformPattern">
/// The TransformPattern control pattern obtained from 
/// an automation element. 
/// </param> 
/// <param name="width">
/// The requested width of the automation element. 
/// </param> 
/// <param name="height">
/// The requested height of the automation element. 
/// </param> 
///-------------------------------------------------------------------- 
private void ResizeElement(
    TransformPattern transformPattern, double width, double height)
{
    try
    {
        if (transformPattern.Current.CanResize)
        {
            transformPattern.Resize(width, height);
        }
    }
    catch (InvalidOperationException)
    {
        // object is not able to perform the requested action 
        return;
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft