첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ LinearGradientBrush 클래스 : 3D 버튼 모양 만들기

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


TestProject.zip


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="LinearGradientBrush 클래스 : 3D 버튼 모양 만들기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Canvas Name="canvas">

        <Ellipse Canvas.Left="50" Canvas.Top="50"

            Width="240"

            Height="100"

            StrokeThickness="15">

            <Ellipse.Fill>

                <LinearGradientBrush StartPoint="0 0" EndPoint="0 1">

                    <GradientStop Color="DarkGreen" Offset="0.0" />

                    <GradientStop Color="LightGreen" Offset="1.0" />

                </LinearGradientBrush>

            </Ellipse.Fill>

            <Ellipse.Stroke>

                <LinearGradientBrush StartPoint="0 0" EndPoint="0 1">

                    <GradientStop Color="LightGreen" Offset="0.0" />

                    <GradientStop Color="DarkGreen" Offset="1.0" />

                </LinearGradientBrush>

            </Ellipse.Stroke>

        </Ellipse>

    </Canvas>

</Window>

 

 

MainWindow.xaml.cs

 

 

using System.Windows;

using System.Windows.Controls;

using System.Windows.Media;

using System.Windows.Shapes;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public partial class MainWindow : Window

    {

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

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

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            InitializeComponent();

 

            Loaded += Window_Loaded;

        }

 

        #endregion

 

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

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

 

        #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)

 

        /// <summary>

        /// 윈도우 로드시 처리하기

        /// </summary>

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

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

        private void Window_Loaded(object sender, RoutedEventArgs e)

        {

            Ellipse ellipse = new Ellipse();

 

            this.canvas.Children.Add(ellipse);

 

            ellipse.Width  = 240;

            ellipse.Height = 100;

 

            Canvas.SetLeft(ellipse, 50 );

            Canvas.SetTop (ellipse, 170);

 

            GradientStop[] fillGradientStopArray =

            {

                new GradientStop(Colors.Brown , 0.0),

                new GradientStop(Colors.Yellow, 1.0)

            };

 

            GradientStopCollection fillGradientStopCollection = new GradientStopCollection(fillGradientStopArray);

 

            LinearGradientBrush fillLinearGradientBrush = new LinearGradientBrush

            (

                fillGradientStopCollection,

                new Point(0.0, 0.0),

                new Point(0.0, 1.0)

            );

 

            ellipse.Fill = fillLinearGradientBrush;

 

            ellipse.StrokeThickness = 15;

 

            GradientStop[] strokeGrandientStopArray =

            {

                new GradientStop(Colors.Yellow, 0.0),

                new GradientStop(Colors.Brown , 1.0)

            };

 

            GradientStopCollection strokeGradientStopCollection = new GradientStopCollection(strokeGrandientStopArray);

 

            LinearGradientBrush strokeLinearGradientBrush = new LinearGradientBrush

            (

                strokeGradientStopCollection,

                new Point(0.0, 0.0),

                new Point(0.0, 1.0)

            );

 

            ellipse.Stroke = strokeLinearGradientBrush;

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker

댓글을 달아 주세요