首页 新闻 会员 周边 捐助

关于圆的位置的问题,WPF高手来看看

0
悬赏园豆:10 [待解决问题]

我自己写的代码,实现的功能是鼠标点到哪,圆就走到哪,但是,问题是 我不知道怎么定义圆的位置,我写的代码如下,高手帮我看看啊:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
Ellipse yuan;
public Window1()
{
InitializeComponent();
yuan
= new Ellipse();
yuan.Fill
= new SolidColorBrush(Colors.Red);
yuan.Width
= 30;
yuan.Height
= 30;
circle.Children.Add(yuan);
Canvas.SetLeft(yuan,
100);
Canvas.SetTop(yuan,
100);

}

private void circle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point p
= e.GetPosition(yuan);
Storyboard storyboard
= new Storyboard();
DoubleAnimation doubleanimation
= new DoubleAnimation(
Canvas.GetLeft(yuan),
p.X,
new Duration(TimeSpan.FromMilliseconds(50)));
Storyboard.SetTarget(doubleanimation, yuan);
Storyboard.SetTargetProperty(doubleanimation,
new PropertyPath("(Canvas.Left)"));
storyboard.Children.Add(doubleanimation);
doubleanimation
= new DoubleAnimation(
Canvas.GetTop(yuan),
p.Y,
new Duration(TimeSpan.FromMilliseconds(50)));
Storyboard.SetTarget(doubleanimation, yuan);
Storyboard.SetTargetProperty(doubleanimation,
new PropertyPath("(Canvas.Top)"));
storyboard.Children.Add(doubleanimation);
if (!Resources.Contains("circleAnimation"))
{
Resources.Add(
"circleAnimation", storyboard);
}
//动画播放
storyboard.Begin();

}
}
}

lmm0629的主页 lmm0629 | 初学一级 | 园豆:190
提问于:2011-07-22 09:17
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册