在Silverlight2 Beta2中实现手写功能
2008-11-07 11:47:36 来源:WEB开发网在page.xaml.cs中添加鼠标MouseLeftButtonDown,MouseMove,MouseLeftButtonUp的事件处理程序来实现手写功能代码如下:
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;
using System.IO;
namespace SilverlightApplication2
{
public partial class Page : UserControl { public Page()
{
InitializeComponent();
}
System.Windows.Ink.Stroke newStroke;
void inkP_MouseLeftButtonDown(object sender, MouseEventArgs e)
{
inkP.CaptureMouse();
newStroke = new System.Windows.Ink.Stroke();
newStroke.DrawingAttributes.Color = Colors.Red;
newStroke.DrawingAttributes.OutlineColor = Colors.Yellow;
newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkP));
inkP.Strokes.Add(newStroke);
}
void inkP_MouseMove(object sender, MouseEventArgs e)
{
if (newStroke != null)
{
newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkP));
}
}
void inkP_MouseLeftButtonUp(object sender, MouseEventArgs e)
{
newStroke = null;
inkP.ReleaseMouseCapture();
}
}
}
1.下面代码用来设置笔画颜色和轮廓颜色:
newStroke.DrawingAttributes.Color = Colors.Red;
newStroke.DrawingAttributes.OutlineColor = Colors.Yellow;
运行项目后效果如下:
上面只是实现了最简单的手写功能,还有很多很多不完善的地方。
Tags:Silverlight 实现
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接