ITransformProvider.Resize(Double, Double) メソッド

定義

コントロールのサイズを変更します。

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

パラメーター

width
Double

ウィンドウの新しい幅 (ピクセル単位)。

height
Double

ウィンドウの新しい高さ (ピクセル単位)。

例外

CanResize プロパティが false の場合。

次の例は、サイズを変更できるカスタム コントロールに対するこのメソッドの実装の 1 つを示しています。

/// <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);
    }));
}
''' <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>
Private Sub Resize(ByVal width As Double, ByVal height As Double) Implements ITransformProvider.Resize
    If Not(CType(Me, ITransformProvider)).CanResize Then
        Throw New InvalidOperationException("Operation cannot be performed.")
    End If

    If width <= 0 Or height <= 0 Then
        Throw New InvalidOperationException("Operation cannot be performed.")
    End If

    Dim widthInt As Integer = CInt(width)
    Dim heightInt As Integer = CInt(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.
    Dim MaxSize As New Size(Me.customControl.formWidth - 20, Me.customControl.formHeight - 20)
    Dim MinSize As New Size(10, 10)

    If widthInt > MaxSize.Width Then
        widthInt = MaxSize.Width
    End If
    If heightInt > MaxSize.Height Then
        heightInt = MaxSize.Height
    End If
    If widthInt < MinSize.Width Then
        widthInt = MinSize.Width
    End If
    If heightInt < MinSize.Height Then
        heightInt = MinSize.Height
    End If

    ' Invoke control method on separate thread to avoid clashing with UI.
    ' Use anonymous method for simplicity.
    Me.customControl.Invoke(New MethodInvoker(Sub() Me.customControl.Size = New Size(widthInt, heightInt)))
End Sub

注釈

分割ペインをサポートするコントロールで呼び出されると、このメソッドは、他の連続したペインのサイズを変更する副作用を持つことができます。

オブジェクトを移動、サイズ変更、または回転することはできません。これにより、結果の画面の位置がコンテナーの座標の外に完全に移動され、キーボードやマウスにアクセスできなくなります。 たとえば、トップレベル ウィンドウが完全に画面外に移動された場合や、子オブジェクトがコンテナーのビューポートの境界の外に移動された場合などです。 このような場合、オブジェクトは要求された画面座標のできるだけ近くに配置され、上部または左の座標はコンテナーの境界内にオーバーライドされます。

適用対象

こちらもご覧ください