Export (0) Print
Expand All

ITransformProvider.Resize Method

Resizes the control.

Namespace:  System.Windows.Automation.Provider
Assembly:  UIAutomationProvider (in UIAutomationProvider.dll)

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

If 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.

The following example shows one possible implementation of this method for a custom control that can be resized.

/// <summary> 
/// Resizes the provider to the specified height and width. 
/// </summary> 
/// <param name="height">The specified height.</param>
/// <param name="width">The specified width.</param>
void ITransformProvider.Resize(double width, double height)
{
    if (!((ITransformProvider)this).CanResize)
        throw new InvalidOperationException("Operation cannot be performed.");

    if (width <= 0 | height <= 0)
        throw new InvalidOperationException("Operation cannot be performed.");

    int widthInt = (int)width;
    int heightInt = (int)height;

    // Resize should never be allowed to place a control outside the  
    // bounds of its container; the control should always be accessible  
    // using the keyboard or mouse. 
    // Use the bounds of the parent window to limit the placement  
    // of the custom control.
    Size MaxSize = 
        new Size(this.customControl.formWidth - 20, 
        this.customControl.formHeight - 20);
    Size MinSize = new Size(10, 10);

    if (widthInt > MaxSize.Width)
        widthInt = MaxSize.Width;
    if (heightInt > MaxSize.Height)
        heightInt = MaxSize.Height;
    if (widthInt < MinSize.Width)
        widthInt = MinSize.Width;
    if (heightInt < MinSize.Height)
        heightInt = MinSize.Height;

    // Invoke control method on separate thread to avoid clashing with UI. 
    // Use anonymous method for simplicity. 
    this.customControl.Invoke(new MethodInvoker(delegate()
    {
        this.customControl.Size = new Size(widthInt, heightInt);
    }));
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2015 Microsoft