WEB开发网
开发学院图形图像Flash 在Silverlight2 Beta2中实现手写功能 阅读

在Silverlight2 Beta2中实现手写功能

 2008-11-07 11:47:36 来源:WEB开发网   
核心提示: 在page.xaml.cs中添加鼠标MouseLeftButtonDown,MouseMove,在Silverlight2 Beta2中实现手写功能(2),MouseLeftButtonUp的事件处理程序来实现手写功能代码如下:using System;using System.Colle

在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;

运行项目后效果如下:

在Silverlight2 Beta2中实现手写功能

上面只是实现了最简单的手写功能,还有很多很多不完善的地方。

上一页  1 2 

Tags:Silverlight 实现

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接