TransformPattern.Resize(Double, Double) 方法

定义

调整控件大小。

public:
 void Resize(double width, double height);
public void Resize (double width, double height);
member this.Resize : double * double -> unit
Public Sub Resize (width As Double, height As Double)

参数

width
Double

窗口的新宽度(以像素为单位)。

height
Double

窗口的新高度(以像素为单位)。

例外

示例

在下面的示例中, TransformPattern 从一个 AutomationElement 控件模式获取,随后用于调整其大小 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>
''' 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 Function GetTransformPattern( _
ByVal targetControl As AutomationElement) As TransformPattern
    Dim transformPattern As TransformPattern = Nothing

    Try
        transformPattern = DirectCast( _
        targetControl.GetCurrentPattern(transformPattern.Pattern), _
        TransformPattern)
    Catch exc As InvalidOperationException
        ' object doesn't support the TransformPattern control pattern
        Return Nothing
    End Try

    Return transformPattern

End Function 'GetTransformPattern
///--------------------------------------------------------------------
/// <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;
    }
}
'''--------------------------------------------------------------------
''' <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 Sub ResizeElement( _
ByVal transformPattern As TransformPattern, _
ByVal width As Double, ByVal height As Double)
    Try
        If transformPattern.Current.CanResize Then
            transformPattern.Resize(width, height)
        End If
    Catch
        ' object is not able to perform the requested action
        Return
    End Try

End Sub

注解

在支持拆分窗格的控件上调用时,此方法可能会产生调整其他连续窗格大小的副作用。

无法移动、调整对象大小或旋转对象,以便其生成的屏幕位置完全超出其容器的坐标,并且无法访问键盘或鼠标。 例如,当顶级窗口完全移出屏幕外或子对象在容器视区边界之外移动时。 在这些情况下,对象尽可能接近所请求的屏幕坐标,并覆盖顶部或左侧坐标,以位于容器边界内。

适用于