첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ DrawingGroup 클래스에서 GuidelineSet 객체를 설정해 드로잉을 만드는 방법을 보여준다.

TestProject.zip
0.01MB

▶ 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"
    Width="800"
    Height="600"
    Title="TestProject"
    FontFamily="나눔고딕코딩"
    FontSize="16">
</Window>

 

▶ MainWindow.xaml.cs

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            #region 창 외부 GeometryDrawing 객체를 생성한다.

            GeometryDrawing windowOuterGeometryDrawing = new GeometryDrawing
            (
                Brushes.Black,
                null,
                new RectangleGeometry(new Rect(0, 20, 30, 80))
            );

            #endregion
            #region 창 내부 GeometryGroup 객체를 생성한다.

            GeometryGroup windowInnerGeometryGroup = new GeometryGroup();

            windowInnerGeometryGroup.Children.Add(new RectangleGeometry(new Rect(5.5, 25, 20, 20)));
            windowInnerGeometryGroup.Children.Add(new RectangleGeometry(new Rect(5.5, 50, 20, 20)));
            windowInnerGeometryGroup.Children.Add(new RectangleGeometry(new Rect(5.5, 75, 20, 20)));

            #endregion
            #region 창 내부 GeometryDrawing 객체를 생성한다.

            GeometryDrawing windowInnerGeometryDrawing = new GeometryDrawing
            (
                Brushes.White,
                null,
                windowInnerGeometryGroup
            );

            #endregion

            #region 왼쪽 창 DrawingGroup을 생성한다.

            DrawingGroup leftWindowDrawingGroup = new DrawingGroup();

            leftWindowDrawingGroup.Children.Add(windowOuterGeometryDrawing);
            leftWindowDrawingGroup.Children.Add(windowInnerGeometryDrawing);

            #endregion
            #region 왼쪽 창 DrawingImage 객체를 생성한다.

            DrawingImage leftWindowDrawingImage = new DrawingImage(leftWindowDrawingGroup);

            leftWindowDrawingImage.Freeze();

            #endregion
            #region 왼쪽 창 Image 객체를 생성한다.

            Image leftWindowImage = new Image();

            leftWindowImage.HorizontalAlignment = HorizontalAlignment.Left;
            leftWindowImage.Margin              = new Thickness(10);
            leftWindowImage.Stretch             = Stretch.None;
            leftWindowImage.Source              = leftWindowDrawingImage;

            #endregion

            #region 오른쪽 창 GuidelineSet 객체를 생성한다.

            GuidelineSet rightWindowGuidelineSet = new GuidelineSet();

            rightWindowGuidelineSet.GuidelinesX.Add( 5.5);
            rightWindowGuidelineSet.GuidelinesX.Add(25.5);
            rightWindowGuidelineSet.GuidelinesY.Add(25  );
            rightWindowGuidelineSet.GuidelinesY.Add(50  );
            rightWindowGuidelineSet.GuidelinesY.Add(75  );

            #endregion
            #region 오른쪽 창 DrawingGroup 객체를 생성한다.

            DrawingGroup rightWindowDrawingGroup = leftWindowDrawingGroup.Clone();

            rightWindowDrawingGroup.GuidelineSet = rightWindowGuidelineSet;

            #endregion
            #region 오른쪽 창 DrawingImage 객체를 생성한다.

            DrawingImage rightWindowDrawingImage = new DrawingImage(rightWindowDrawingGroup);

            rightWindowDrawingImage.Freeze();

            #endregion
            #region 오른쪽 창 Image 객체를 생성한다.

            Image rightWindowImage = new Image();

            rightWindowImage.HorizontalAlignment = HorizontalAlignment.Left;
            rightWindowImage.Margin              = new Thickness(50, 10, 10, 10);
            rightWindowImage.Stretch             = Stretch.None;
            rightWindowImage.Source              = rightWindowDrawingImage;

            #endregion

            #region StackPanel 객체를 생성한다.

            StackPanel stackPanel = new StackPanel();

            stackPanel.Margin      = new Thickness(20);
            stackPanel.Orientation = Orientation.Horizontal;

            stackPanel.Children.Add(leftWindowImage );
            stackPanel.Children.Add(rightWindowImage);

            #endregion

            #region 배경 격자 사각형 GeometryDrawing 객체를 생성한다.

            GeometryDrawing backgroundGridRectangleGeometryDrawing = new GeometryDrawing
            (
                Brushes.White,
                null,
                new RectangleGeometry(new Rect(0, 0, 1, 1))
            );

            #endregion
            #region 배경 격자 수직선 PolyLineSegment 객체를 생성한다.

            PolyLineSegment backgroundGridVerticalLinePolyLineSegment = new PolyLineSegment();

            backgroundGridVerticalLinePolyLineSegment.Points.Add(new Point(1, 0  ));
            backgroundGridVerticalLinePolyLineSegment.Points.Add(new Point(1, 0.1));
            backgroundGridVerticalLinePolyLineSegment.Points.Add(new Point(0, 0.1));

            #endregion
            #region 배경 격자 수직선 PathFigure 객체를 생성한다.

            PathFigure backgroundGridVerticalLinePathFigure = new PathFigure();

            backgroundGridVerticalLinePathFigure.Segments.Add(backgroundGridVerticalLinePolyLineSegment);

            #endregion
            #region 배경 격자 수직선 PathGeometry 객체를 생성한다.

            PathGeometry backgroundGridVerticalLinePathGeometry = new PathGeometry();

            backgroundGridVerticalLinePathGeometry.Figures.Add(backgroundGridVerticalLinePathFigure);

            #endregion
            #region 배경 격자 수직선 GeometryDrawing 객체를 생성한다.

            GeometryDrawing backgroundGridVerticalLineGeometryDrawing = new GeometryDrawing
            (
                new SolidColorBrush(Color.FromArgb(255,204,204,255)),
                null,
                backgroundGridVerticalLinePathGeometry
            );

            #endregion
            #region 배경 격자 수평선 PolyLineSegment 객체를 생성한다.

            PolyLineSegment backgroundGridHorizontalLinePolyLineSegment = new PolyLineSegment();

            backgroundGridHorizontalLinePolyLineSegment.Points.Add(new Point(0  , 1));
            backgroundGridHorizontalLinePolyLineSegment.Points.Add(new Point(0.1, 1));
            backgroundGridHorizontalLinePolyLineSegment.Points.Add(new Point(0.1, 0));

            #endregion
            #region 배경 격자 수평선 PathFigure 객체를 생성한다.

            PathFigure backgroundGridHorizontalLinePathFigure = new PathFigure();

            backgroundGridHorizontalLinePathFigure.Segments.Add(backgroundGridHorizontalLinePolyLineSegment);

            #endregion
            #region 배경 격자 수평선 PathGeometry 객체를 생성한다.

            PathGeometry backgroundGridHorizontalLinePathGeometry = new PathGeometry();

            backgroundGridHorizontalLinePathGeometry.Figures.Add(backgroundGridHorizontalLinePathFigure);

            #endregion
            #region 배경 격자 수평선 GeometryDrawing 객체를 생성한다.

            GeometryDrawing backgroundGridHorizontalLineGeometryDrawing = new GeometryDrawing
            (
                new SolidColorBrush(Color.FromArgb(255, 204, 204, 255)),
                null,
                backgroundGridHorizontalLinePathGeometry
            );

            #endregion
            #region 배경 격자 DrawingGroup 객체를 생성한다.

            DrawingGroup backgroundGridDrawingGroup = new DrawingGroup();

            backgroundGridDrawingGroup.Children.Add(backgroundGridRectangleGeometryDrawing);
            backgroundGridDrawingGroup.Children.Add(backgroundGridVerticalLineGeometryDrawing  );
            backgroundGridDrawingGroup.Children.Add(backgroundGridHorizontalLineGeometryDrawing);

            #endregion
            #region 배경 격자 DrawingBrush 객체를 생성한다.

            DrawingBrush backgroundGridDrawingBrush = new DrawingBrush(backgroundGridDrawingGroup);

            backgroundGridDrawingBrush.ViewportUnits = BrushMappingMode.Absolute;
            backgroundGridDrawingBrush.Viewport      = new Rect(0, 0, 10, 10);
            backgroundGridDrawingBrush.TileMode      = TileMode.Tile;

            backgroundGridDrawingBrush.Freeze();

            #endregion

            #region border 객체를 생성한다.

            Border border = new Border();

            border.HorizontalAlignment = HorizontalAlignment.Center;
            border.VerticalAlignment   = VerticalAlignment.Center;
            border.BorderThickness     = new Thickness(1);
            border.BorderBrush         = Brushes.Gray;
            border.Background          = backgroundGridDrawingBrush;
            border.Child               = stackPanel;

            #endregion

            Content = border;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요