ITransformProvider.Resize(Double, Double) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
調整控制鍵大小。
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 性質是假的。
範例
以下範例展示了一種可用於可調整大小的自訂控制方法的實作。
/// <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
備註
當呼叫支援分割窗格的控制項時,這種方法可能會產生調整其他相鄰窗格大小的副作用。
物件無法被移動、調整大小或旋轉,使其產生的螢幕位置完全超出容器座標,且鍵盤或滑鼠無法存取。 例如,當頂層視窗完全移出畫面外,或子物件移出容器視窗的邊界時。 在這些情況下,物件會盡量靠近請求的螢幕座標,而頂部或左側的座標會被覆寫,以使其位於容器的邊界內。