블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
반응형

Category

Recent Post

Recent Comment

Archive

2009. 12. 1. 16:00 .Net Project/SilverLight 3.0
반응형
  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
                                                  (ipPen_MouseLeftButtonDown);

            this.ipPen.MouseMove += new MouseEventHandler(ipPen_MouseMove);

            this.ipPen.MouseLeftButtonUp += new MouseButtonEventHandler
                                                  (ipPen_MouseLeftButtonUp);

            this.ipPen.MouseLeave += new MouseEventHandler(ipPen_MouseLeave);

 

            this.ipPen.LostMouseCapture += new MouseEventHandler
                                           (ipPen_LostMouseCapture);

 

            this.btnCleare.Click += new RoutedEventHandler(btnCleare_Click);

 

            this.ipPen.KeyDown += new KeyEventHandler(ipPen_KeyDown);

            this.LayoutRoot.KeyDown += new KeyEventHandler
                            (LayoutRoot_KeyDown);
//[D] Pen Color Changed

         }

       
        
void LayoutRoot_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);

            }

        }


       
//KeyDown Event

        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 버튼 클릭시 클리어
        void btnCleare_Click(object sender, RoutedEventArgs e)

        {

            ipPen.Strokes.Clear();

        }

        //마우스 캡쳐를 잃었을 때...

        void ipPen_LostMouseCapture(object sender, MouseEventArgs e)

        {

            stroke = null;

        }

       

        private void InitializePen()

        {

            this.stroke.DrawingAttributes.Color = 
                 ((
SolidColorBrush)brush).Color; //[C] Pen 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
                                     (e.StylusDevice.GetStylusPoints(ipPen));

            }           

            //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
posted by Magic_kit