Windows Phone development (21): Make a simple drawing board turn: http://blog.csdn.net/tcjiaan/article/details/7392179

Source: Internet
Author: User

In fact, what we want to talk about today is a control-inkpresenter. This control is not very powerful and cannot be compared with inkcanvas in WPF. It is estimated that it is rarely used in actual development. However, let's take a look at it. After all, it's not difficult to use it.

 

This control has no technical content. Pay attention to the following points:

1. The width and height of inkpresenter must be specified explicitly, that is, automatic values and margin cannot be used. Otherwise, ink marks cannot be collected unless there are child elements in them;

2. To collect ink marks, set the clip attribute;

3. You can use the drawingattributes class to set the ink size and color.

 

This control cannot automatically collect ink marks like WPF does. That is to say, we can only write our own code.

 

[HTML]View plaincopyprint?

  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>

 

[CSHARP]View plaincopyprint?

  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. // Introduce the following namespace.
  14. Using system. Windows. Ink;
  15. Namespace inkpresentsample
  16. {
  17. Public partial class mainpage: phoneapplicationpage
  18. {
  19. Stroke currentstroke = NULL;
  20. // Constructor
  21. Public mainpage ()
  22. {
  23. Initializecomponent ();
  24. // Set the clip to collect ink marks
  25. Rectanglegeometry Rg = new rectanglegeometry ();
  26. // The final height of the control should be used to make the range accurate.
  27. RG. rect = new rect (0, 0, mypresenter. actualwidth, mypresenter. actualheight );
  28. Mypresenter. Clip = RG;
  29. }
  30. Private void mypresenter_mouseleftbuttondown (Object sender, mousebuttoneventargs E)
  31. {
  32. // Capture the mouse and cursor when we click
  33. Mypresenter. capturemouse ();
  34. // Collect the points at which the current cursor is located
  35. Styluspointcollection SC = new styluspointcollection ();
  36. SC. Add (E. stylusdevice. getstyluspoints (mypresenter ));
  37. Currentstroke = new stroke (SC );
  38. // Set the stroke color and size
  39. Currentstroke. drawingattributes. Color = colors. Yellow;
  40. Currentstroke. drawingattributes. width = 8;
  41. Currentstroke. drawingattributes. Height = 8;
  42. // Add new strokes to the set
  43. Mypresenter. Strokes. Add (currentstroke );
  44. }
  45. Private void mypresenter_lostmousecapture (Object sender, mouseeventargs E)
  46. {
  47. // When the mouse is released, the reference of the stroke variable is also released.
  48. Currentstroke = NULL;
  49. }
  50. Private void mypresenter_mousemove (Object sender, mouseeventargs E)
  51. {
  52. If (currentstroke! = NULL)
  53. {
  54. // Each time you move the mouse, the corresponding points are collected.
  55. Currentstroke. styluspoints. Add (E. stylusdevice. getstyluspoints (mypresenter ));
  56. }
  57. }
  58. }
  59. }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.