ITransformProvider.Move Method (Double, Double)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Moves the control.

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

Sub Move (
	x As Double,
	y As Double


Type: System.Double

Absolute screen coordinates of the left side of the control.

Type: System.Double

Absolute screen coordinates of the top of the control.

Exception Condition

If the CanMove property is false.

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

''' <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

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top