■ 필기장 사용하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


StylusToolDialog.xaml

 

 

<Window x:Class="TestProject.StylusToolWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="clr-namespace:TestProject"

    ShowInTaskbar="False"

    WindowStartupLocation="CenterOwner"

    SizeToContent="WidthAndHeight"

    ResizeMode="NoResize"

    Title="스타일러스 도구">

    <Grid Margin="6">

        <Grid.ColumnDefinitions>

            <ColumnDefinition />

            <ColumnDefinition />

        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>

            <RowDefinition />

            <RowDefinition />

            <RowDefinition />

            <RowDefinition />

            <RowDefinition />

        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Grid.Column="0">

            <Grid.RowDefinitions>

                <RowDefinition />

                <RowDefinition />

                <RowDefinition />

            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>

                <ColumnDefinition />

                <ColumnDefinition />

                <ColumnDefinition />

            </Grid.ColumnDefinitions>

            <Label Grid.Row="0" Grid.Column="0"

                Margin="6 6 0 6"

                Content="너비(_W) :" />

            <TextBox Name="widthTextBox" Grid.Row="0" Grid.Column="1"

                Margin="0 6 0 6"

                Width="50"

                TextAlignment="Right" />

            <Label Grid.Row="0" Grid.Column="2"

                Margin="0 6 6 6"

                Content="포인트" />

            <Label Grid.Row="1" Grid.Column="0"

                Margin="6 6 0 6"

                Content="높이(_H) :" />

            <TextBox Name="heightTextBox" Grid.Row="1" Grid.Column="1"

                Margin="0 6 0 6"

                Width="50"

                TextAlignment="Right" />

            <Label Grid.Row="1" Grid.Column="2"

                Margin="0 6 6 6"

                Content="포인트" />

            <Label Grid.Row="2" Grid.Column="0"

                Margin="6 6 0 6"

                Content="회전(_R) : " />

            <TextBox Name="angleTextBox" Grid.Row="2" Grid.Column="1"

                Margin="0 6 0 6"

                Width="50"

                TextAlignment="Right" />

            <Label Grid.Row="2" Grid.Column="2"

                Margin="0 6 6 6"

                Content="도" />

        </Grid>

        <GroupBox Grid.Row="1" Grid.Column="0"

            Margin="6"

            Header="스타일러스 팁(_S)">

            <StackPanel>

                <RadioButton Name="ellipseRadioButton"

                    Margin="6"

                    Content="Ellipse" />

                <RadioButton Name="rectangleRadioButton"

                    Margin="6"

                Content="Rectangle" />

            </StackPanel>

        </GroupBox>

        <CheckBox Name="ignorePressureCheckBox" Grid.Row="2" Grid.Column="0"

            Margin="12 6 6 6"

            Content="압력 무시(_I)" />

        <CheckBox Name="highlighterCheckBox" Grid.Row="3" Grid.Column="0"

            Margin="12 6 6 6"

            Content="하이라이트(_H)" />

        <local:ColorListBox x:Name="colorListBox" Grid.Row="0" Grid.Column="1" Grid.RowSpan="3"

            Margin="6"

            Width="150"

            Height="200" />

        <UniformGrid Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"

            Columns="2">

            <Button Name="okButton"

                Margin="6"

                HorizontalAlignment="Center"

                MinWidth="60"

                IsDefault="True"

                Content="확인"

                Click="okButton_Click" />

            <Button

                Margin="6"

                HorizontalAlignment="Center"

                MinWidth="60"

                IsCancel="True"

                Content="Cancel" />

        </UniformGrid>

    </Grid>

</Window>

 

 

StylusToolDialog.xaml.cs

 

 

using System;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Ink;

using System.Windows.Media;

 

namespace TestProject

{

    /// <summary>

    /// 스타일러스 도구 윈도우

    /// </summary>

    public partial class StylusToolWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 드로잉 어트리뷰트 - DrawingAttributes

 

        /// <summary>

        /// 드로잉 어트리뷰트

        /// </summary>

        public DrawingAttributes DrawingAttributes

        {

            set

            {

                this.heightTextBox.Text = (0.75 * value.Height).ToString("F1");

                this.widthTextBox.Text  = (0.75 * value.Width ).ToString("F1");

                this.angleTextBox.Text  = (180 * Math.Acos(value.StylusTipTransform.M11) / Math.PI).ToString("F1");

 

                this.ignorePressureCheckBox.IsChecked = value.IgnorePressure;

                this.highlighterCheckBox.IsChecked    = value.IsHighlighter;

 

                if(value.StylusTip == StylusTip.Ellipse)

                {

                    this.ellipseRadioButton.IsChecked = true;

                }

                else

                {

                    this.rectangleRadioButton.IsChecked = true;

                }

 

                this.colorListBox.SelectedColor = value.Color;

 

                this.colorListBox.ScrollIntoView(this.colorListBox.SelectedColor);

            }

            get

            {

                DrawingAttributes drawingAttributes = new DrawingAttributes();

 

                drawingAttributes.Height = Double.Parse(this.heightTextBox.Text) / 0.75;

                drawingAttributes.Width  = Double.Parse(this.widthTextBox.Text ) / 0.75;

 

                drawingAttributes.StylusTipTransform = new RotateTransform(Double.Parse(this.angleTextBox.Text)).Value;

 

                drawingAttributes.IgnorePressure = (bool)this.ignorePressureCheckBox.IsChecked;

                drawingAttributes.IsHighlighter  = (bool)this.highlighterCheckBox.IsChecked;

                drawingAttributes.StylusTip      = (bool)this.ellipseRadioButton.IsChecked ? StylusTip.Ellipse : StylusTip.Rectangle;

 

                drawingAttributes.Color = this.colorListBox.SelectedColor;

 

                return drawingAttributes;

            }

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - StylusToolWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public StylusToolWindow()

        {

            InitializeComponent();

 

            this.widthTextBox.TextChanged  += textBox_TextChanged;

            this.heightTextBox.TextChanged += textBox_TextChanged;

            this.angleTextBox.TextChanged  += textBox_TextChanged;

 

            this.widthTextBox.Focus();

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 텍스트 박스 텍스트 변경시 처리하기 - textBox_TextChanged(sender, e)

 

        /// <summary>

        /// 텍스트 박스 텍스트 변경시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void textBox_TextChanged(object sender, TextChangedEventArgs e)

        {

            double width;

            double height;

            double angle;

 

            this.okButton.IsEnabled = Double.TryParse(this.widthTextBox.Text, out width)   &&

                                      width / 0.75 >= DrawingAttributes.MinWidth           &&

                                      width / 0.75 <= DrawingAttributes.MaxWidth           &&

                                      Double.TryParse(this.heightTextBox.Text, out height) &&

                                      height / 0.75 >= DrawingAttributes.MinHeight         &&

                                      height / 0.75 <= DrawingAttributes.MaxHeight         &&

                                      Double.TryParse(this.angleTextBox.Text, out angle);

        }

 

        #endregion

        #region OK 버튼 클릭시 처리하기 - okButton_Click(sender, e)

 

        /// <summary>

        /// OK 버튼 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void okButton_Click(object sender, RoutedEventArgs e)

        {

            DialogResult = true;

        }

 

        #endregion

    }

}

 

 

EraserToolDialog.cs

 

 

using System;

using System.Windows;

using System.Windows.Ink;

 

namespace TestProject

{

    /// <summary>

    /// 지우개 도구 윈도우

    /// </summary>

    public class EraserToolWindow : StylusToolWindow

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 지우개 모양 - EraserShape

 

        /// <summary>

        /// 지우개 모양

        /// </summary>

        public StylusShape EraserShape

        {

            set

            {

                this.heightTextBox.Text = (0.75 * value.Height).ToString("F1");

                this.widthTextBox.Text  = (0.75 * value.Width ).ToString("F1");

                this.angleTextBox.Text  = value.Rotation.ToString();

 

                if(value is EllipseStylusShape)

                {

                    this.ellipseRadioButton.IsChecked = true;

                }

                else

                {

                    this.rectangleRadioButton.IsChecked = true;

                }

            }

            get

            {

                StylusShape stylusShape;

 

                double width  = Double.Parse(this.widthTextBox.Text ) / 0.75;

                double height = Double.Parse(this.heightTextBox.Text) / 0.75;

                double angle  = Double.Parse(this.angleTextBox.Text );

 

                if((bool)this.ellipseRadioButton.IsChecked)

                {

                    stylusShape = new EllipseStylusShape(width, height, angle);

                }

                else

                {

                    stylusShape = new RectangleStylusShape(width, height, angle);

                }

 

                return stylusShape;

            }

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - EraserToolWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public EraserToolWindow()

        {

            Title = "지우개 도구";

 

            this.ignorePressureCheckBox.Visibility = Visibility.Collapsed;

            this.highlighterCheckBox.Visibility    = Visibility.Collapsed;

            this.colorListBox.Visibility           = Visibility.Collapsed;

        }

 

        #endregion

    }

}

 

 

MainWindow.xaml

 

 

<Window x:Class="TestProject.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:src="clr-namespace:TestProject"

    SizeToContent="WidthAndHeight"

    Title="필기장 사용하기">

    <DockPanel>

        <Menu DockPanel.Dock="Top"

            FontFamily="나눔고딕코딩"

            FontSize="16">

            <MenuItem Header="파일(_F)">

                <MenuItem Header="새 문서(_N)"      Command="New"  />

                <MenuItem Header="문서 열기(_O)..." Command="Open" />

                <MenuItem Header="문서 저장(_S)..." Command="Save" />

                <Separator />

                <MenuItem Header="종료(_X)" Command="Close" />

            </MenuItem>

            <MenuItem

                Header="편집(_E)"

                SubmenuOpened="editMenuItem_SubmenuOpened">

                <MenuItem Header="잘라내기(_T)" Command="Cut"    />

                <MenuItem Header="복사(_C)"     Command="Copy"   />

                <MenuItem Header="붙여넣기(_P)" Command="Paste"  />

                <MenuItem Header="삭제(_D)"     Command="Delete" />

                <Separator />

                <MenuItem Header="전체 선택(_A)" Command="SelectAll" />

                <MenuItem Name="formatMenuItem"

                    Header="포맷 선택(_F)..."

                    Click="formatMenuItem_Click" />

            </MenuItem>

            <MenuItem

                Header="스타일러스 모드(_S)"

                SubmenuOpened="stylusModeMenuItem_SubmenuOpened">

                <MenuItem

                    Header="잉크(_I)"

                    Click="stylusModeChildMenuItem_Click"

                    Tag="{x:Static InkCanvasEditingMode.Ink}" />

                <MenuItem

                    Header="포인트 삭제(_P)"

                    Click="stylusModeChildMenuItem_Click"

                    Tag="{x:Static InkCanvasEditingMode.EraseByPoint}" />

                <MenuItem

                    Header="스트로크 삭제(_E)"

                    Click="stylusModeChildMenuItem_Click"

                    Tag="{x:Static InkCanvasEditingMode.EraseByStroke}" />

                <MenuItem

                    Header="선택(_S)"

                    Click="stylusModeChildMenuItem_Click"

                    Tag="{x:Static InkCanvasEditingMode.Select}" />

            </MenuItem>

            <MenuItem Name="eraserModeMenuItem"

                Header="지우개 모드(_R)"

                SubmenuOpened="eraserModeMenuItem_SubmenuOpened">

                <MenuItem

                    Header="잉크(_I)"

                    Click="eraserModeChildMenuItem_Click"

                    Tag="{x:Static InkCanvasEditingMode.Ink}" />

                <MenuItem

                    Header="포인트 삭제(_P)"

                    Click="eraserModeChildMenuItem_Click"

                    Tag="{x:Static InkCanvasEditingMode.EraseByPoint}" />

                <MenuItem

                    Header="스트로크 삭제(_E)"

                    Click="eraserModeChildMenuItem_Click"

                    Tag="{x:Static InkCanvasEditingMode.EraseByStroke}" />

                <MenuItem

                    Header="선택(_S)"

                    Click="eraserModeChildMenuItem_Click"

                    Tag="{x:Static InkCanvasEditingMode.Select}" />

            </MenuItem>

            <MenuItem Header="도구(_T)">

                <MenuItem

                    Header="스타일러스(_S)..."

                    Click="stylusToolMenuItem_Click" />

                <MenuItem

                    Header="지우개(_E)..."

                    Click="eraserToolMenuItem_Click" />

            </MenuItem>

        </Menu>

        <ScrollViewer VerticalScrollBarVisibility="Auto">

            <InkCanvas Name="inkCanvas"

                Width="{x:Static src:MainWindow.CanvasWidth}"

                Height="{x:Static src:MainWindow.CanvasHeight}"

                Background="LemonChiffon">

                <Line

                    Stroke="Red"

                    X1="0.875in"

                    Y1="0"

                    X2="0.875in"

                    Y2="{x:Static src:MainWindow.CanvasHeight}" />

                <Line

                    Stroke="Red"

                    X1="0.9375in"

                    Y1="0"

                    X2="0.9375in"

                    Y2="{x:Static src:MainWindow.CanvasHeight}" />

            </InkCanvas>

        </ScrollViewer>

    </DockPanel>

    <Window.CommandBindings>

        <CommandBinding Command="New"       Executed="New_Executed"                                 />

        <CommandBinding Command="Open"      Executed="Open_Executed"                                />

        <CommandBinding Command="Save"      Executed="Save_Executed"                                />

        <CommandBinding Command="Close"     Executed="Close_Executed"                               />

        <CommandBinding Command="Cut"       Executed="Cut_Executed"    CanExecute="Cut_CanExecute"  />

        <CommandBinding Command="Copy"      Executed="Copy_Executed"   CanExecute="Cut_CanExecute"  />

        <CommandBinding Command="Paste"     Executed="Paste_Executed" CanExecute="Paste_CanExecute" />

        <CommandBinding Command="Delete"    Executed="Delete_Executed" CanExecute="Cut_CanExecute"  />

        <CommandBinding Command="SelectAll" Executed="SelectAll_Executed"                           />

    </Window.CommandBindings>

</Window>

 

 

MainWindow.xaml.cs

 

 

using Microsoft.Win32;

using System;

using System.IO;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Markup;

using System.Windows.Media;

using System.Windows.Shapes;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public partial class MainWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Public

 

        #region Field

 

        /// <summary>

        /// 캔버스 너비 (8인치)

        /// </summary>

        public static readonly double CanvasWidth = 8 * 96;

 

        /// <summary>

        /// 캔버스 높이 (8인치)

        /// </summary>

        public static readonly double CanvasHeight = 8 * 96;

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            InitializeComponent();

 

            double y = 96;

 

            while(y < CanvasHeight)

            {

                Line line = new Line();

 

                line.X1     = 0;

                line.Y1     = y;

                line.X2     = CanvasWidth;

                line.Y2     = y;

                line.Stroke = Brushes.LightBlue;

 

                this.inkCanvas.Children.Add(line);

 

                y += 24; // 0.25인치

            }

 

            if(Tablet.TabletDevices.Count == 0)

            {

                this.eraserModeMenuItem.Visibility = Visibility.Collapsed;

            }

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region New 실행시 처리하기 - New_Executed(sender, e)

 

        /// <summary>

        /// New 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void New_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            this.inkCanvas.Strokes.Clear();

        }

 

        #endregion

        #region Open 실행시 처리하기 - Open_Executed(sender, e)

 

        /// <summary>

        /// Open 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Open_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            OpenFileDialog openFileDialog = new OpenFileDialog();

 

            openFileDialog.CheckFileExists = true;

            openFileDialog.Filter          = "Ink Serialized Format (*.isf)|*.isf|All files (*.*)|*.*";

 

            if((bool)openFileDialog.ShowDialog(this))

            {

                try

                {

                    FileStream fileStream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read);

 

                    this.inkCanvas.Strokes = new StrokeCollection(fileStream);

 

                    fileStream.Close();

                }

                catch(Exception exception)

                {

                    MessageBox.Show(exception.Message, Title);

                }

            }

        }

 

        #endregion

        #region Save 실행시 처리하기 - Save_Executed(sender, e)

 

        /// <summary>

        /// Save 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Save_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            SaveFileDialog saveFileDialog = new SaveFileDialog();

 

            saveFileDialog.Filter = "Ink Serialized Format (*.isf)|*.isf|XAML Drawing File (*.xaml)|*.xaml|All files (*.*)|*.*";

 

            if((bool)saveFileDialog.ShowDialog(this))

            {

                try

                {

                    FileStream fileStream = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write);

 

                    if(saveFileDialog.FilterIndex == 1 || saveFileDialog.FilterIndex == 3)

                    {

                        this.inkCanvas.Strokes.Save(fileStream);

                    }

                    else

                    {

                        DrawingGroup drawingGroup = new DrawingGroup();

 

                        foreach(Stroke stroke in this.inkCanvas.Strokes)

                        {

                            Color color = stroke.DrawingAttributes.Color;

 

                            if(stroke.DrawingAttributes.IsHighlighter)

                            {

                                color = Color.FromArgb(128, color.R, color.G, color.B);

                            }

 

                            drawingGroup.Children.Add

                            (

                                new GeometryDrawing

                                (

                                    new SolidColorBrush(color),

                                    null,

                                    stroke.GetGeometry()

                                )

                            );

                        }

 

                        XamlWriter.Save(drawingGroup, fileStream);

                    }

 

                    fileStream.Close();

                }

                catch(Exception exception)

                {

                    MessageBox.Show(exception.Message, Title);

                }

            }

        }

 

        #endregion

        #region Close 실행시 처리하기 - Close_Executed(sender, e)

 

        /// <summary>

        /// Close 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Close_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            Close();

        }

 

        #endregion

 

        #region Edit 메뉴 항목 하위 메뉴 오픈시 처리하기 - editMenuItem_SubmenuOpened(sender, e)

 

        /// <summary>

        /// Edit 메뉴 항목 하위 메뉴 오픈시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void editMenuItem_SubmenuOpened(object sender, RoutedEventArgs e)

        {

            this.formatMenuItem.IsEnabled = this.inkCanvas.GetSelectedStrokes().Count > 0;

        }

 

        #endregion

        #region Cut 실행시 처리하기 - Cut_Executed(sender, e)

        

        /// <summary>

        /// Cut 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Cut_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            this.inkCanvas.CutSelection();

        }

 

        #endregion

        #region Cut 실행 가능 여부 처리하기 - Cut_CanExecute(sender, e)

 

        /// <summary>

        /// Cut 실행 가능 여부 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Cut_CanExecute(object sender, CanExecuteRoutedEventArgs e)

        {

            e.CanExecute = this.inkCanvas.GetSelectedStrokes().Count > 0;

        }

 

        #endregion

        #region Copy 실행시 처리하기 - Copy_Executed(sender, e)

 

        /// <summary>

        /// Copy 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Copy_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            this.inkCanvas.CopySelection();

        }

 

        #endregion

        #region Paste 실행시 처리하기 - Paste_Executed(sender, e)

 

        /// <summary>

        /// Paste 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Paste_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            this.inkCanvas.Paste();

        }

 

        #endregion

        #region Paste 실행 가능 여부 처리하기 - Paste_CanExecute(sender, e)

 

        /// <summary>

        /// Paste 실행 가능 여부 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Paste_CanExecute(object sender, CanExecuteRoutedEventArgs e)

        {

            e.CanExecute = this.inkCanvas.CanPaste();

        }

 

        #endregion

        #region Delete 실행시 처리하기 - Delete_Executed(sender, e)

 

        /// <summary>

        /// Delete 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Delete_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            foreach(Stroke stroke in inkCanvas.GetSelectedStrokes())

            {

                this.inkCanvas.Strokes.Remove(stroke);

            }

        }

 

        #endregion

        #region Select All 실행시 처리하기 - SelectAll_Executed(sender, e)

 

        /// <summary>

        /// Select All 실행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void SelectAll_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            this.inkCanvas.Select(this.inkCanvas.Strokes);

        }

 

        #endregion

        #region Format 메뉴 항목 클릭시 처리하기 - formatMenuItem_Click(sender, e)

 

        /// <summary>

        /// Format 메뉴 항목 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void formatMenuItem_Click(object sender, RoutedEventArgs e)

        {

            StylusToolWindow stylusToolWindow = new StylusToolWindow();

 

            stylusToolWindow.Owner = this;

            stylusToolWindow.Title = "포맷 선택";

 

            StrokeCollection strokeCollection = this.inkCanvas.GetSelectedStrokes();

 

            if(strokeCollection.Count > 0)

            {

                stylusToolWindow.DrawingAttributes = strokeCollection[0].DrawingAttributes;

            }

            else

            {

                stylusToolWindow.DrawingAttributes = inkCanvas.DefaultDrawingAttributes;

            }

 

            if((bool)stylusToolWindow.ShowDialog().GetValueOrDefault())

            {

                foreach(Stroke stroke in strokeCollection)

                {

                    stroke.DrawingAttributes = stylusToolWindow.DrawingAttributes;

                }

            }

        }

 

        #endregion

 

        #region 스타일러스 모드 메뉴 항목 하위 메뉴 오픈시 처리하기 - stylusModeMenuItem_SubmenuOpened(sender, e)

 

        /// <summary>

        /// 스타일러스 모드 메뉴 항목 하위 메뉴 오픈시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void stylusModeMenuItem_SubmenuOpened(object sender, RoutedEventArgs e)

        {

            MenuItem menuItem = sender as MenuItem;

 

            foreach(MenuItem childMenuItem in menuItem.Items)

            {

                childMenuItem.IsChecked = this.inkCanvas.EditingMode == (InkCanvasEditingMode)childMenuItem.Tag;

            }

        }

 

        #endregion

        #region 스타일러스 모드 자식 메뉴 항목 클릭시 처리하기 - stylusModeChildMenuItem_Click(sender, e)

 

        /// <summary>

        /// 스타일러스 모드 자식 메뉴 항목 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void stylusModeChildMenuItem_Click(object sender, RoutedEventArgs e)

        {

            MenuItem menuItem = sender as MenuItem;

 

            this.inkCanvas.EditingMode = (InkCanvasEditingMode)menuItem.Tag;

        }

 

        #endregion

        #region 지우개 모드 메뉴 항목 하위 메뉴 오픈시 처리하기 - eraserModeMenuItem_SubmenuOpened(sender, e)

 

        /// <summary>

        /// 지우개 모드 메뉴 항목 하위 메뉴 오픈시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void eraserModeMenuItem_SubmenuOpened(object sender, RoutedEventArgs e)

        {

            MenuItem menuItem = sender as MenuItem;

 

            foreach(MenuItem childMenuItem in menuItem.Items)

            {

                childMenuItem.IsChecked = this.inkCanvas.EditingModeInverted == (InkCanvasEditingMode)childMenuItem.Tag;

            }

        }

 

        #endregion

        #region 지우개 모드 자식 메뉴 항목 클릭시 처리하기 - eraserModeChildMenuItem_Click(sender, e)

 

        /// <summary>

        /// 지우개 모드 자식 메뉴 항목 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void eraserModeChildMenuItem_Click(object sender, RoutedEventArgs e)

        {

            MenuItem menuItem = sender as MenuItem;

 

            this.inkCanvas.EditingModeInverted = (InkCanvasEditingMode)menuItem.Tag;

        }

 

        #endregion

 

        #region 스타일러스 도구 메뉴 항목 클릭시 처리하기 - stylusToolMenuItem_Click(sender, e)

 

        /// <summary>

        /// 스타일러스 도구 메뉴 항목 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void stylusToolMenuItem_Click(object sender, RoutedEventArgs e)

        {

            StylusToolWindow stylusToolWindow = new StylusToolWindow();

 

            stylusToolWindow.Owner             = this;

            stylusToolWindow.DrawingAttributes = this.inkCanvas.DefaultDrawingAttributes;

 

            if((bool)stylusToolWindow.ShowDialog().GetValueOrDefault())

            {

                this.inkCanvas.DefaultDrawingAttributes = stylusToolWindow.DrawingAttributes;

            }

        }

 

        #endregion

        #region 지우개 도구 메뉴 항목 클릭시 처리하기 - eraserToolMenuItem_Click(sender, e)

 

        /// <summary>

        /// 지우개 도구 메뉴 항목 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void eraserToolMenuItem_Click(object sender, RoutedEventArgs e)

        {

            EraserToolWindow eraserToolWindow = new EraserToolWindow();

 

            eraserToolWindow.Owner       = this;

            eraserToolWindow.EraserShape = this.inkCanvas.EraserShape;

 

            if((bool)eraserToolWindow.ShowDialog().GetValueOrDefault())

            {

                this.inkCanvas.EraserShape = eraserToolWindow.EraserShape;

            }

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요