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

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"
    Title="MessageBox 클래스 : 메시지 박스 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16"
    SizeToContent="WidthAndHeight">
    <Window.Resources>
        <Style TargetType="{x:Type Label}">
            <Setter Property="Margin" Value="5" />
        </Style>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Margin" Value="5" />
        </Style>
        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="Margin" Value="5" />
        </Style>
    </Window.Resources>
    <Grid Margin="10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Label Grid.Row="0" Grid.Column="0"
            Content="소유자 윈도우 연결 여부" />
        <CheckBox Name="ownerWindowCheckBox" Grid.Row="0" Grid.Column="1"
            VerticalAlignment="Center" />
        <Label Grid.Row="1" Grid.Column="0"
            Content="메시지" />
        <TextBox Name ="messageTextBox" Grid.Row="1" Grid.Column="1"
            VerticalContentAlignment="Center"
            Text="샘플 메시지" />
        <Label Grid.Row="2" Grid.Column="0"
            Content="제목" />
        <TextBox Name="captionTextBox" Grid.Row="2" Grid.Column="1"
            VerticalContentAlignment="Center"
            Text="제목" />
        <Label Grid.Row="3" Grid.Column="0"
            Content="버튼" />
        <ComboBox Name="messageBoxButtonComboBox" Grid.Row="3" Grid.Column="1">
            <ComboBoxItem IsSelected="True">OK</ComboBoxItem>
            <ComboBoxItem>OKCancel</ComboBoxItem>
            <ComboBoxItem>YesNo</ComboBoxItem>
            <ComboBoxItem>YesNoCancel</ComboBoxItem>
        </ComboBox>
        <Label Grid.Row="4" Grid.Column="0" 
            Content="아이콘" />
        <ComboBox Name="messageBoxImageComboBox" Grid.Row="4" Grid.Column="1">
            <ComboBoxItem>Asterisk</ComboBoxItem>
            <ComboBoxItem>Error</ComboBoxItem>
            <ComboBoxItem>Exclamation</ComboBoxItem>
            <ComboBoxItem>Hand</ComboBoxItem>
            <ComboBoxItem>Information</ComboBoxItem>
            <ComboBoxItem IsSelected="True">None</ComboBoxItem>
            <ComboBoxItem>Question</ComboBoxItem>
            <ComboBoxItem>Stop</ComboBoxItem>
            <ComboBoxItem>Warning</ComboBoxItem>
        </ComboBox>
        <Label Grid.Row="5" Grid.Column="0"
            Content="디폴트 결과" />
        <ComboBox Name="messageBoxResultComboBox" Grid.Row="5" Grid.Column="1">
            <ComboBoxItem>Cancel</ComboBoxItem>
            <ComboBoxItem>No</ComboBoxItem>
            <ComboBoxItem IsSelected="True">None</ComboBoxItem>
            <ComboBoxItem>OK</ComboBoxItem>
            <ComboBoxItem>Yes</ComboBoxItem>
        </ComboBox>
        <Label Grid.Row="6" Grid.Column="0"
            Content="옵션" />
        <ComboBox Name="messageBoxOptionsComboBox" Grid.Row="6" Grid.Column="1">
            <ComboBoxItem>DefaultDesktopOnly</ComboBoxItem>
            <ComboBoxItem IsSelected="True">None</ComboBoxItem>
            <ComboBoxItem>RightAlign</ComboBoxItem>
            <ComboBoxItem>RtlReading</ComboBoxItem>
            <ComboBoxItem>ServiceNotification</ComboBoxItem>
        </ComboBox>
        <Button Grid.Row="7" Grid.Column="1" 
            Margin="5"
            Padding="5"
            Content="Test"
            Click="testButton_Click" />
        <StatusBar Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2"
            Margin="0 5 0 0"
            Padding="5">
            <StatusBarItem>
                <TextBlock Name="resultTextBlock"
                    FontFamily="나눔고딕코딩"
                    FontSize="16"
                    Text="대기" />
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System;
using System.Windows;

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

        #region 생성자 - MainWindow()

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

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

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

        /// <summary>
        /// Test 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void testButton_Click(object sender, RoutedEventArgs e)
        {
            Window window = ((bool)this.ownerWindowCheckBox.IsChecked ? this : null);

            string            message           = this.messageTextBox.Text;
            string            caption           = this.captionTextBox.Text;
            MessageBoxButton  messageBoxButton  = (MessageBoxButton )Enum.Parse(typeof(MessageBoxButton ), this.messageBoxButtonComboBox.Text );
            MessageBoxImage   messageBoxImage   = (MessageBoxImage  )Enum.Parse(typeof(MessageBoxImage  ), this.messageBoxImageComboBox.Text  );
            MessageBoxResult  messageBoxResult  = (MessageBoxResult )Enum.Parse(typeof(MessageBoxResult ), this.messageBoxResultComboBox.Text );
            MessageBoxOptions messageBoxOptions = (MessageBoxOptions)Enum.Parse(typeof(MessageBoxOptions), this.messageBoxOptionsComboBox.Text);

            MessageBoxResult resultMessageBoxResult;

            if(window == null)
            {
                resultMessageBoxResult = MessageBox.Show(message, caption, messageBoxButton, messageBoxImage, messageBoxResult, messageBoxOptions);
            }
            else
            {
                resultMessageBoxResult = MessageBox.Show(window, message, caption, messageBoxButton, messageBoxImage, messageBoxResult, messageBoxOptions);
            }
            
            this.resultTextBlock.Text = "결과 = " + resultMessageBoxResult.ToString();
        }

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

댓글을 달아 주세요