现在的位置: 首页 > 综合 > 正文

silverlight鼠标事件获取point

2013年01月08日 ⁄ 综合 ⁄ 共 1343字 ⁄ 字号 评论关闭

XAML代码:

<UserControl x:Class="SilverlightApplication50.EventMouse"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable
="d"
d:DesignHeight
="300" d:DesignWidth="400"
Width
="780" Height="300">
<Canvas Background="GreenYellow" MouseMove="Canvas_MouseMove">
<TextBlock Canvas.Left="20" Canvas.Top="20" FontSize="20"
Text
="Mouse Event"/>
<Button x:Name="mybutton" Width="100" Height="20"></Button>
<TextBlock x:Name="TextBlock1" Canvas.Left="20" Canvas.Top="240" FontSize="20" Text="Point:" ></TextBlock>
</Canvas>
</UserControl>

 

cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication50
{
public partial class EventMouse : UserControl
{
public EventMouse()
{
InitializeComponent();
}

private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
Point p =e.GetPosition(null);

this.mybutton.SetValue(Canvas.LeftProperty, p.X);
this.mybutton.SetValue(Canvas.TopProperty, p.Y);

this.TextBlock1.Text = string.Format("X坐标是{0},Y坐标是{1}", p.X, p.Y);
}
}
}
【上篇】
【下篇】

抱歉!评论已关闭.