自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows Phone開發(fā)(21):做一個(gè)簡單的繪圖板

移動(dòng)開發(fā)
Windows Phone是微軟發(fā)布的一款手機(jī)操作系統(tǒng),它將微軟旗下的Xbox Live游戲、Xbox Music音樂與獨(dú)特的視頻體驗(yàn)整合至手機(jī)中。

其實(shí)我們今天要說的就是一個(gè)控件——InkPresenter,這個(gè)控件并不是十分強(qiáng)大,沒辦法和WPF中的InkCanvas相比,估計(jì)在實(shí)際開發(fā)中也很少可能會(huì)用到它,不過,我們還是來了解一下吧,畢竟用起來也不難。

使用該控件沒有什么技術(shù)含量,注意一下以下幾點(diǎn)就是了:

1、必須明確指定InkPresenter的寬度和高度,也就是不能使用自動(dòng)值和Margin,不然不能收集墨跡,除非里面有子元素;

2、要收集墨跡,要設(shè)置Clip屬性;

3、可以使用DrawingAttributes類設(shè)置墨跡的大小和顏色。

該控件不能像WPF那樣自動(dòng)實(shí)現(xiàn)收集墨跡的功能,也就是說只能是我們自己寫代碼了。

  1. <Grid> 
  2.     <InkPresenter x:Name="MyPresenter"  
  3.                   HorizontalAlignment="Left" 
  4.                   VerticalAlignment="Top"  
  5.                   MouseLeftButtonDown="MyPresenter_MouseLeftButtonDown" 
  6.                   LostMouseCapture="MyPresenter_LostMouseCapture" 
  7.                   MouseMove="MyPresenter_MouseMove" 
  8.                   Background="Transparent" 
  9.                   Opacity="1" Width="480" Height="750" /> 
  10. </Grid>
  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Net; 
  5. using System.Windows; 
  6. using System.Windows.Controls; 
  7. using System.Windows.Documents; 
  8. using System.Windows.Input; 
  9. using System.Windows.Media; 
  10. using System.Windows.Media.Animation; 
  11. using System.Windows.Shapes; 
  12. using Microsoft.Phone.Controls; 
  13. // 引入以下命名空間。 
  14. using System.Windows.Ink; 
  15. namespace InkPresentSample 
  16.     public partial class MainPage : PhoneApplicationPage 
  17.     { 
  18.         Stroke CurrentStroke = null
  19.         // 構(gòu)造函數(shù) 
  20.         public MainPage() 
  21.         { 
  22.             InitializeComponent(); 
  23.             // 設(shè)置剪輯,以便收集墨跡 
  24.             RectangleGeometry rg = new RectangleGeometry(); 
  25.             // 為了使范圍準(zhǔn)確,應(yīng)使用控件的最終呈現(xiàn)高度。 
  26.             rg.Rect = new Rect(0, 0, MyPresenter.ActualWidth, MyPresenter.ActualHeight); 
  27.             MyPresenter.Clip = rg; 
  28.         } 
  29.         private void MyPresenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
  30.         { 
  31.             // 當(dāng)我們點(diǎn)擊時(shí)獲捉鼠標(biāo)光標(biāo) 
  32.             MyPresenter.CaptureMouse(); 
  33.             // 收集當(dāng)前的光標(biāo)所在的位置的點(diǎn) 
  34.             StylusPointCollection sc = new StylusPointCollection(); 
  35.             sc.Add(e.StylusDevice.GetStylusPoints(MyPresenter)); 
  36.             CurrentStroke = new Stroke(sc); 
  37.             // 設(shè)置筆觸的顏色,大小 
  38.             CurrentStroke.DrawingAttributes.Color = Colors.Yellow; 
  39.             CurrentStroke.DrawingAttributes.Width = 8; 
  40.             CurrentStroke.DrawingAttributes.Height = 8; 
  41.             // 把新的筆觸添加到集合中 
  42.             MyPresenter.Strokes.Add(CurrentStroke); 
  43.         } 
  44.         private void MyPresenter_LostMouseCapture(object sender, MouseEventArgs e) 
  45.         { 
  46.             // 當(dāng)釋放鼠標(biāo)時(shí),也同時(shí)釋放筆觸變量的引用 
  47.             CurrentStroke = null
  48.         } 
  49.         private void MyPresenter_MouseMove(object sender, MouseEventArgs e) 
  50.         { 
  51.             if (CurrentStroke != null
  52.             { 
  53.                 // 每移動(dòng)一次鼠標(biāo),都收集對(duì)應(yīng)的點(diǎn)。 
  54. CurrentStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyPresenter)); 
  55.             } 
  56.         } 
  57.     } 

責(zé)任編輯:閆佳明 來源: oschina
相關(guān)推薦

2013-04-23 17:11:47

Windows Pho用Express Bl

2020-07-20 10:00:52

Python翻譯工具命令行

2011-02-28 09:22:47

SQLite記賬簿

2015-07-03 11:27:30

程序員自己神器

2011-09-08 13:41:53

Widget

2023-05-26 16:42:28

2023-05-27 21:13:34

FlaskURL裝飾器

2010-07-05 15:18:01

Windows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2009-08-25 01:46:00

C# WINDOWS服

2010-04-21 17:07:54

Windows Pho

2018-01-04 16:04:35

圓環(huán)放大動(dòng)畫

2011-06-08 10:24:38

Windows Pho 應(yīng)用程序

2011-06-08 10:01:36

Windows Pho 應(yīng)用程序

2010-11-05 10:40:55

Windows Pho

2011-02-22 17:33:36

Windows Pho

2010-08-06 11:14:35

SilverlightWindows PhoWindows Pho

2023-04-11 09:12:31

北向應(yīng)用開發(fā)鴻蒙

2011-03-15 19:45:27

Windows Azu

2017-06-30 15:18:24

對(duì)賬系統(tǒng)互聯(lián)網(wǎng)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)