Make an object follow the mouse pointer as it moves on the screen.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="mouseMoveWithPointer" Height="400" Width="500">
<Canvas MouseMove="MouseMoveHandler" Background="Red">
<Ellipse Name="ellipse" Fill="LightBlue" Width="100" Height="100"/>
</Canvas>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Shapes
Imports System.Windows.Input
Namespace WpfApplication1
Public Partial Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub MouseMoveHandler(sender As Object, e As MouseEventArgs)
' Get the x and y coordinates of the mouse pointer.
Dim position As Point = e.GetPosition(Me)
Dim pX As Double = position.X
Dim pY As Double = position.Y
ellipse.Width = pX
ellipse.Height = pY
End Sub
End Class
End Namespace
Related examples in the same category