ITransformProvider.Move(Double, Double) 메서드

정의

컨트롤을 이동합니다.

public:
 void Move(double x, double y);
public void Move (double x, double y);
abstract member Move : double * double -> unit
Public Sub Move (x As Double, y As Double)

매개 변수

x
Double

컨트롤 왼쪽의 절대 화면 좌표입니다.

y
Double

컨트롤 위쪽의 절대 화면 좌표입니다.

예외

CanMove 속성이 false인 경우

예제

다음 예제에서는 이동할 수 있는 사용자 지정 컨트롤에 대 한이 메서드의 가능한 구현을 보여 주세요.

/// <summary>
/// Moves the provider to the specified position.
/// </summary>
/// <param name="x">The specified X screen coordinate.</param>
/// <param name="y">The specified Y screen coordinate</param>
void ITransformProvider.Move(double x, double y)
{
    int leftInt = (int)x;
    int topInt = (int)y;

    if (!((ITransformProvider)this).CanMove)
        throw new InvalidOperationException(
            "Operation cannot be performed.");

    // Move 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.
    int maxLeft = 10;
    int maxTop = 10;
    int maxRight =
        this.customControl.formWidth - this.customControl.Width - 10;
    int maxBottom =
        this.customControl.formHeight - this.customControl.Height - 10;

    if (leftInt < maxLeft)
        leftInt = 0;
    if (topInt < maxTop)
        topInt = 0;
    if (leftInt > maxRight)
        leftInt = maxRight;
    if (topInt > maxBottom)
        topInt = maxBottom;

    // Invoke control method on separate thread to avoid clashing with UI.
    // Use anonymous method for simplicity.
    this.customControl.Invoke(new MethodInvoker(delegate ()
    {
        this.customControl.Left = leftInt;
        this.customControl.Top = topInt;
    }));
}
''' <summary>
''' Moves the provider to the specified position.
''' </summary>
''' <param name="x">The specified X screen coordinate.</param>
''' <param name="y">The specified Y screen coordinate</param>
Private Sub Move(ByVal x As Double, ByVal y As Double) Implements ITransformProvider.Move
    Dim leftInt As Integer = CInt(x)
    Dim topInt As Integer = CInt(y)

    If Not(CType(Me, ITransformProvider)).CanMove Then
        Throw New InvalidOperationException("Operation cannot be performed.")
    End If

    ' Move 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 maxLeft As Integer = 10
    Dim maxTop As Integer = 10
    Dim maxRight As Integer = Me.customControl.formWidth - Me.customControl.Width - 10
    Dim maxBottom As Integer = Me.customControl.formHeight - Me.customControl.Height - 10

    If leftInt < maxLeft Then
        leftInt = 0
    End If
    If topInt < maxTop Then
        topInt = 0
    End If
    If leftInt > maxRight Then
        leftInt = maxRight
    End If
    If topInt > maxBottom Then
        topInt = maxBottom
    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.Left = leftInt
        Me.customControl.Top = topInt
    End Sub))
End Sub

설명

개체 이동, 크기를 조정 하거나 결과 화면 위치가 컨테이너의 및 키보드 또는 마우스에 액세스할 수 없도록 좌표 완전히 것 회전할 수 없습니다. 예를 들어, 최상위 창이 화면에서 완전히 벗어나거나 이동할 때 또는 자식 개체의 컨테이너의 뷰포트 경계 외부에 이동 됩니다. 이러한 경우 개체는 컨테이너 경계 내에 있도록 재정의 위쪽 또는 왼쪽 좌표를 사용 하 여 최대한 요청 된 화면 좌표를 가깝게 배치 됩니다.

적용 대상

추가 정보