InkPresenter Control - |
InkPresenter.Xaml <UserControl x:Class="RiaInkPresenter.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <StackPanel> <Button x:Name="btnCleare" Background="Blue" Width="400" Height="25" Content="삭íe제|" FontSize="15"></Button> <InkPresenter x:Name="ipPen" Background="Silver" Width="400" Height="300"> </InkPresenter> </StackPanel> </Grid> </UserControl> InkPresenter.CS 실행화면..) 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.Windows.Ink; namespace RiaInkPresenter { public partial class MainPage : UserControl { //Stroke Shape Type : Pen Shape private Stroke stroke; private Brush brush = new SolidColorBrush(Colors.Red); //[A] Pen Save public MainPage() { InitializeComponent(); ////Click Event this.ipPen.MouseLeftButtonDown += new MouseButtonEventHandler this.ipPen.MouseMove += new MouseEventHandler(ipPen_MouseMove); this.ipPen.MouseLeftButtonUp += new MouseButtonEventHandler this.ipPen.MouseLeave += new MouseEventHandler(ipPen_MouseLeave); this.ipPen.LostMouseCapture += new MouseEventHandler this.btnCleare.Click += new RoutedEventHandler(btnCleare_Click); this.ipPen.KeyDown += new KeyEventHandler(ipPen_KeyDown); this.LayoutRoot.KeyDown += new KeyEventHandler
{ //RGB Color if (e.Key == Key.R) { brush = new SolidColorBrush(Colors.Red); //[B] Pen Color Red } else if (e.Key == Key.G) { brush = new SolidColorBrush(Colors.Green); } else if (e.Key == Key.B) { brush = new SolidColorBrush(Colors.Blue); } else { brush = new SolidColorBrush(Colors.Black); } }
void ipPen_KeyDown(object sender, KeyEventArgs e) { //RGB Color if (e.Key == Key.R){ brush = new SolidColorBrush(Colors.Red); //[B] Pen Color Red } else if (e.Key == Key.G){ brush = new SolidColorBrush(Colors.Green); } else if (e.Key == Key.B){ brush = new SolidColorBrush(Colors.Blue); } else{ brush = new SolidColorBrush(Colors.Black); } } //Click 버튼 클릭시 클리어 { ipPen.Strokes.Clear(); } //마우스 캡쳐를 잃었을 때... void ipPen_LostMouseCapture(object sender, MouseEventArgs e) { stroke = null; } private void InitializePen() { this.stroke.DrawingAttributes.Color = this.stroke.DrawingAttributes.OutlineColor = Colors.Black; } //영역 벗어 날때 처리.. void ipPen_MouseLeave(object sender, MouseEventArgs e) { ipPen_MouseLeftButtonUp(null, null); //메서드 호출 void ipPen_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ipPen.ReleaseMouseCapture();//Mouse Capture stroke = null; } void ipPen_MouseMove(object sender, MouseEventArgs e) { if (stroke != null) { //stroke = new Stroke(e.StylusDevice.GetStylusPoints(ipPen)); this.stroke.StylusPoints.Add } //ipPen.Strokes.Add(stroke); } void ipPen_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ipPen.CaptureMouse(); //마우스 위치 캡쳐 ////현재 잉크 영역에서 마우스 캡쳐 this.stroke = new Stroke(e.StylusDevice.GetStylusPoints(ipPen)); ////First Loading... InitializePen(); //펜 색상 초기화 ////모양 출력 ipPen.Strokes.Add(stroke); } } } |
'.Net Project > SilverLight 3.0' 카테고리의 다른 글
48장 ComboBox 컨트롤 (0) | 2009.12.02 |
---|---|
47장 RoutedEventArgs 컨트롤 (0) | 2009.12.01 |
45장) Drag&Drop 컨트롤 (0) | 2009.12.01 |
42장) ScrollViewer 컨트롤 (0) | 2009.12.01 |
41장) ToolTip 컨트롤 (0) | 2009.12.01 |