zoukankan      html  css  js  c++  java
  • silverlight 画图InkPresenter

     1 <UserControl x:Class="SilverlightTest.PolygonTest"
     2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     4     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     5     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     6     xmlns:controls="clr-namespace:Custom.Controls;assembly=Custom.Controls"
     7     mc:Ignorable="d"
     8     d:DesignHeight="400" d:DesignWidth="800">
     9 
    10     <Canvas x:Name="LayoutRoot" Width="900" Height="400">
    11         <Canvas.Background>
    12             <ImageBrush ImageSource="/SilverlightTest;component/Images/map.png" Stretch="None" />
    13         </Canvas.Background>
    14 
    15         <Rectangle Margin="0" Stroke="Black" Width="900" Height="400" />
    16         <InkPresenter x:Name="MyIP" Width="900" Height="400" Margin="0" MouseLeftButtonDown="MyIP_MouseLeftButtonDown" 
    17                       LostMouseCapture="MyIP_LostMouseCapture" MouseMove="MyIP_MouseMove" Background="Transparent" Opacity="1">
    18         </InkPresenter>
    19         <!--<Polygon MouseEnter="OnMouseEnter" MouseLeave="OnMouseLeave" Fill="#FF000000" Opacity="0.5" Visibility="Visible" StrokeThickness="1" Stroke="#FF222935" 
    20                  Points="219,122 221,124 221,128 221,132 221,135 221,138 221,141 221,145 221,148 221,151 221,154 
    21         222,157 223,161 227,166 228,170 231,171 234,172 236,174 236,178 237,181 238,183 238,186 238,190 238,193 238,196 239,200 240,204 241,209 241,212 242,215 
    22         243,218 243,221 243,224 244,226 245,228 247,231 248,233 250,235 252,237 254,238 255,240 256,243 256,247 256,250 256,253 257,257 257,260 257,263 259,266 
    23         258,268 259,266 260,269 260,272 260,276 261,279 264,282 266,285 267,287 269,290 271,293 274,296 278,299 281,300 284,297 284,300 284,303 284,306 284,309 
    24         285,313 286,315 287,318 288,322 290,325 291,329 293,334 295,335 297,337 301,339 304,339 309,339 312,340 315,343 318,345 321,347 323,348 326,348 328,347 
    25         330,345 332,340 335,337 337,334 339,331 342,332 345,333 346,336 346,339 344,340 344,343 342,344 341,347 342,350 343,353 343,357 345,360 348,361 351,361 
    26         355,359 357,356 359,354 362,351 365,349 367,345 369,343 370,340 373,338 374,335 377,333 379,330 381,326 383,324 386,322 387,319 388,316 389,313 389,310 
    27         389,307 389,303 389,300 389,297 389,293 390,291 391,287 389,285 386,282 384,280 382,278 379,279 376,279 374,280 371,280 368,279 368,276 367,274 368,272 
    28         371,268 374,265 375,263 377,259 378,255 379,253 381,251 385,251 387,249 389,246 389,243 389,240 389,237 389,233 389,230 389,227 388,223 386,221 384,218 
    29         381,216 379,217 379,220 378,223 376,226 376,229 376,233 374,237 372,239 370,240 369,236 368,234 367,231 364,230 361,230 359,232 358,234 358,237 356,241 
    30         354,243 352,244 350,245 347,243 345,241 344,238 343,236 343,233 343,230 343,226 340,225 337,224 335,225 333,224 332,222 330,219 329,216 328,213 328,210 
    31         327,207 327,203 327,200 327,197 327,193 327,190 327,187 327,184 325,180 324,177 323,174 321,172 319,169 318,166 317,161 315,158 313,156 311,153 310,151 
    32         309,148 308,145 305,141 303,139 300,136 299,133 297,130 295,129 293,128 291,126 288,124 286,119 285,116 283,112 281,109 278,107 277,105 275,101 273,98 
    33         272,96 270,94 267,93 265,91 263,89 260,87 256,86 253,86 251,84 249,83 246,79 245,77 242,72 239,71 236,69 233,68 229,68 224,67 219,67 218,65 220,63 222,59 
    34         223,57 221,55 218,54 215,57 211,59 209,60 206,61 204,58 200,55 198,53 196,52 192,51 190,50 188,48 185,47 182,46 180,43 180,40 178,38 177,36 174,33 172,30 
    35         170,29 168,28 167,26 164,25 160,23 157,21 154,19 151,18 148,18 144,18 143,16 140,14 137,11 134,10 132,9 129,9 125,8 123,7 120,7 116,6 113,6 111,8 110,12 
    36         109,16 106,17 103,17 100,17 97,16 94,15 91,14 87,13 83,12 80,12 77,12 73,12 69,14 65,14 61,14 58,14 55,14 51,12 47,12 44,14 41,16 38,16 35,17 33,19 32,21 
    37         32,25 34,27 36,28 39,29 41,31 43,33" />-->
    38         <!-- 55,77,28 -->
    39     </Canvas>
    40 </UserControl>
    View Code
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Shapes;
    
    namespace SilverlightTest
    {
        public partial class PolygonTest : UserControl
        {
            Stroke NewStroke;
    
            public PolygonTest()
            {
                InitializeComponent();
                SetBoundary();
            }
    
            private void OnMouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
            {
                Polygon pl = sender as Polygon;
                if (pl == null) return;
                SetProperty(pl, 0, 2);
            }
    
            private void OnMouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
            {
                Polygon pl = sender as Polygon;
                if (pl == null) return;
                SetProperty(pl, 0.5, 1);
            }
    
            private void SetProperty(Polygon pl, double opacity, double thickness) 
            {
                pl.Opacity = opacity;
                pl.StrokeThickness = thickness;
            }
    
            private void SetBoundary()
            {
                RectangleGeometry MyRectangleGeometry = new RectangleGeometry();
                MyRectangleGeometry.Rect = new Rect(0, 0, MyIP.ActualWidth, MyIP.ActualHeight);
                MyIP.Clip = MyRectangleGeometry;
            }
    
            private void MyIP_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                MyIP.CaptureMouse();
                StylusPointCollection MyStylusPointCollection = new StylusPointCollection();
                MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP));
                NewStroke = new Stroke(MyStylusPointCollection);
                MyIP.Strokes.Add(NewStroke);
            }
    
            private void MyIP_LostMouseCapture(object sender, System.Windows.Input.MouseEventArgs e)
            {
                string str = string.Empty;
                int index = 0;
                foreach (var item in NewStroke.StylusPoints)
                {
                    if (index % 3 == 0)
                        str += item.X.ToString() + "," + item.Y.ToString() + " ";
                    index++;
                }
                str = str.Trim();
                MessageBox.Show(str);
                NewStroke = null;
            }
    
            private void MyIP_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
            {
                if (NewStroke != null)
                    NewStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP));
            }
        }
    }
    View Code
  • 相关阅读:
    12月4日
    12月3日
    12月2日
    12月1日
    11月30日
    11月29日
    11月28日
    11月27日
    jquery mobile-按钮控件
    ap web
  • 原文地址:https://www.cnblogs.com/zxbzl/p/3712029.html
Copyright © 2011-2022 走看看