zoukankan      html  css  js  c++  java
  • windows phone画板程序

              前几天想要这样一个程序,没找到,今天上网偶然发现了,转载过来。

        

    <Grid>  
        <InkPresenter x:Name="MyPresenter"   
                      HorizontalAlignment="Left"  
                      VerticalAlignment="Top"   
                      MouseLeftButtonDown="MyPresenter_MouseLeftButtonDown"  
                      LostMouseCapture="MyPresenter_LostMouseCapture"  
                      MouseMove="MyPresenter_MouseMove"  
                      Background="Transparent"  
                      Opacity="1" Width="480" Height="750" />  
    </Grid>  

          

    [csharp] view plaincopyprint?
    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 Microsoft.Phone.Controls;  
    // 引入以下命名空间。  
    using System.Windows.Ink;  
      
    namespace InkPresentSample  
    {  
        public partial class MainPage : PhoneApplicationPage  
        {  
            Stroke CurrentStroke = null;  
            // 构造函数  
            public MainPage()  
            {  
                InitializeComponent();  
      
                // 设置剪辑,以便收集墨迹  
                RectangleGeometry rg = new RectangleGeometry();  
                // 为了使范围准确,应使用控件的最终呈现高度。  
                rg.Rect = new Rect(0, 0, MyPresenter.ActualWidth, MyPresenter.ActualHeight);  
                MyPresenter.Clip = rg;  
            }  
      
            private void MyPresenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)  
            {  
                // 当我们点击时获捉鼠标光标  
                MyPresenter.CaptureMouse();  
                // 收集当前的光标所在的位置的点  
                StylusPointCollection sc = new StylusPointCollection();  
                sc.Add(e.StylusDevice.GetStylusPoints(MyPresenter));  
                CurrentStroke = new Stroke(sc);  
                // 设置笔触的颜色,大小  
                CurrentStroke.DrawingAttributes.Color = Colors.Yellow;  
                CurrentStroke.DrawingAttributes.Width = 8;  
                CurrentStroke.DrawingAttributes.Height = 8;  
                // 把新的笔触添加到集合中  
                MyPresenter.Strokes.Add(CurrentStroke);  
            }  
      
            private void MyPresenter_LostMouseCapture(object sender, MouseEventArgs e)  
            {  
                // 当释放鼠标时,也同时释放笔触变量的引用  
                CurrentStroke = null;  
            }  
      
            private void MyPresenter_MouseMove(object sender, MouseEventArgs e)  
            {  
                if (CurrentStroke != null)  
                {  
                    // 每移动一次鼠标,都收集对应的点。  
                    CurrentStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyPresenter));  
                }  
            }  
        }  
    }  

    我试了运行结果是正确 的,有需要的试试。

  • 相关阅读:
    .Net转Java自学之路—SpringMVC框架篇九(拦截器)
    .Net转Java自学之路—SpringMVC框架篇八(RESTful支持)
    移动端高清适配、布局开发解决方案
    Webpack+Gulp+React+ES6开发
    gulp使用gulp-file-include将header/footer引入页面
    git在window与linux的换行符问题
    文件(图片)上传组件
    ie8、9跨域上传文件(图片)
    移动端rem布局背景图片使用以及sprite雪碧图
    iOS/Android 浏览器(h5)及微信中唤起本地APP
  • 原文地址:https://www.cnblogs.com/learnWindowsPhone/p/2468948.html
Copyright © 2011-2022 走看看