Silverlight3.0 使用墨迹画笔InkPresenter
InkPresenter称为墨迹控件,它支持的输入设备有, 手写笔输入,触摸板和鼠标输入.其使用方法非常简单.只需添加 InkPresenter控件,并保存InkPresenter的Storkes对象即可.
XAML代码如下:
<Grid x:Name="LayoutRoot" Background="White"> <InkPresenter x:Name="IP" Margin="0,8,8,8" MouseMove="IP_MouseMove" LostMouseCapture="IP_LostMouseCapture" MouseLeftButtonDown="IP_MouseLeftButtonDown"> <InkPresenter.Background> <ImageBrush ImageSource="4.jpg" Stretch="Fill"/> </InkPresenter.Background> </InkPresenter> </Grid>
C#后台代码如下:
//定义一个画笔 private Stroke myStroke; private void IP_MouseMove(object sender, MouseEventArgs e) { if (myStroke != null) { //当鼠标移动时如果画笔不为空就继续添加,新的坐标点到StylusPoints集合 myStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(IP)); } } private void IP_LostMouseCapture(object sender, MouseEventArgs e) { myStroke = null; } private void IP_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //墨迹画笔捕获鼠标 IP.CaptureMouse(); //创建画笔做标集合SPC StylusPointCollection SPC = new StylusPointCollection(); //将当前IP对象的坐标集合添加到SPC SPC.Add(e.StylusDevice.GetStylusPoints(IP)); //将坐标添加到画笔对象 myStroke = new Stroke(SPC); //墨迹尺寸 myStroke.DrawingAttributes.Width = 10; myStroke.DrawingAttributes.Height = 10; //墨迹颜色 myStroke.DrawingAttributes.Color = Colors.White; //将画笔对象添加到IP的画笔集合中 IP.Strokes.Add(myStroke); }
效果图:
哦哦,字写的不好看,大家凑合看吧…
阳光明媚..哈哈