Note that there are some explanatory texts on larger screens.

plurals
  1. POObject the follow the cursor of the mouse
    primarykey
    data
    text
    <p>i am doing a Wpf Application and i create a Control with the shape of an eye ,i put a Ellipse(eye) in a Canvas and my purpose is when the cursor of the mouse enter in the Canvas the Ellipse follow the cursor of mouse. Do you have any suggestion how perform this task? Thanks so much for your attention.</p> <p>Cheers</p> <h1>EDIT</h1> <p>I have update my code in Xaml:</p> <pre><code>&lt;Window Height="480" Title="Window2" Width="640" x:Class="WpfApplication5.Window2" x:Name="Window" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Window.Resources&gt; &lt;Storyboard x:Key="OnLoaded1"&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetName="ctrCircle" Storyboard.TargetProperty="(UIElement.RenderTransform).( TransformGroup.Children)[3].(TranslateTransform.X)"&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="1"&gt; &lt;EasingDoubleKeyFrame.EasingFunction&gt; &lt;ExponentialEase EasingMode="EaseOut" /&gt; &lt;/EasingDoubleKeyFrame.EasingFunction&gt; &lt;/EasingDoubleKeyFrame&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetName="ctrCircle" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"&gt; &lt;EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="1"&gt; &lt;EasingDoubleKeyFrame.EasingFunction&gt; &lt;ExponentialEase EasingMode="EaseOut" /&gt; &lt;/EasingDoubleKeyFrame.EasingFunction&gt; &lt;/EasingDoubleKeyFrame&gt; &lt;/DoubleAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;Style TargetType="Ellipse"&gt; &lt;Setter Property="RenderTransform"&gt; &lt;Setter.Value&gt; &lt;ScaleTransform ScaleX="1" ScaleY="1"/&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="RenderTransformOrigin" Value="0.5,0.5"/&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Canvas MouseMove="mov" x:Name="LayoutRoot"&gt; &lt;Border ackground="Black" B="" Canvas.Left="178" Canvas.Top="103" CornerRadius="250" Height="255.5" Width="290" x:Name="border_eye"&gt; &lt;Ellipse Fill="#FFFFC600" Height="12" HorizontalAlignment="Left" Margin="0" RenderTransformOrigin="0.5,0.5" Stroke="{x:Null}" VerticalAlignment="Center" Visibility="Visible" Width="12" x:Name="ctrCircle"&gt; &lt;Ellipse.RenderTransform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform /&gt; &lt;SkewTransform /&gt; &lt;RotateTransform /&gt; &lt;TranslateTransform /&gt; &lt;/TransformGroup&gt; &lt;/Ellipse.RenderTransform&gt; &lt;/Ellipse&gt; &lt;/Border&gt; &lt;/Canvas&gt; &lt;/Window&gt; </code></pre> <p>and in the code behind :</p> <pre><code>private void mov(object sender, MouseEventArgs e) { System.Windows.Point pt = e.GetPosition((Canvas)sender); Storyboard invokeStoryboard = this.Resources["OnLoaded1"] as Storyboard; ((DoubleAnimationUsingKeyFrames)invokeStoryboard.Children[0]).KeyFrames[0].Value = pt.X; ((DoubleAnimationUsingKeyFrames)invokeStoryboard.Children[1]).KeyFrames[0].Value = pt.Y; invokeStoryboard.Begin(); } </code></pre> <p>now my purpose is when i move the mouse in the Canvas area(LayoutRoot) the Ellipse(ctrCircle) move only inside the Border(border_eye) and don't overcome the area of the "border_eye" this effect is similar an eye.</p> <p>Do you have any input to work out this step?</p> <p>Thanks so much </p> <p>Have a nice day.</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload