WPF 메시지 박스(MessageBox) & 툴팁(ToolTip)
MessageBox는 사용자에게 어떤 메시지를 보여주기 위한 것으로 대화상자 라고도 한다. 아래 예제를 통해 메시지박스 사용법에 대해 이해하자.
n MainWindow.xaml
<Window x:Class="MessageBoxTest.MainWindow"
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"
xmlns:local="clr-namespace:MessageBoxTest"
mc:Ignorable="d"
Title="MainWindow" Height="150" Width="350">
<StackPanel>
<Button Content="2버튼" Click="Button2_Click">
<Button.ToolTip>
<ToolTip>
<StackPanel>
<TextBlock FontWeight="Bold">버튼두개짜리</TextBlock>
<TextBlock>2버튼 메시지박스 테스트 입니다.</TextBlock>
</StackPanel>
</ToolTip>
</Button.ToolTip>
</Button>
<Button Content="3버튼" Click="Button3_Click">
<Button.ToolTip>
<ToolTip>
<StackPanel>
<TextBlock FontWeight="Bold">버튼세개짜리</TextBlock>
<TextBlock>3버튼 메시지박스 테스트 입니다.</TextBlock>
</StackPanel>
</ToolTip>
</Button.ToolTip>
</Button>
<TextBlock Name="tb" Margin="30" HorizontalAlignment="Center">메시지 박스 응답 결과...</TextBlock>
</StackPanel>
</Window>
|
n MainWindow.xaml.cs
using System;
using System.Windows;
namespace MessageBoxTest
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button2_Click(object sender, RoutedEventArgs e)
{
// 두개의 버튼(yes, no)를 가지는 메시지 박스
MessageBoxResult result = MessageBox.Show("YES/NO를 선택하세요. ",
"2버튼 메시지 박스 테스트",
MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
tb.Text = "2버튼 YES 클릭";
}
else
{
tb.Text = "2버튼 NO 클릭";
}
}
private void Button3_Click(object sender, RoutedEventArgs e)
{
//YesNoCancel 버튼, Question icon을 가지는 메시지 박스
MessageBoxResult result = MessageBox.Show("메시지",
"타이틀(Question 메시지박스,YesNoCancel)",
MessageBoxButton.YesNoCancel,
MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
tb.Text = "3버튼 YES 클릭";
}
else if (result == MessageBoxResult.No)
{
tb.Text = "3버튼 NO 클릭";
}
else if (result == MessageBoxResult.Cancel)
{
tb.Text = "3버튼 CANCEL 클릭";
}
}
}}
|
댓글 없음:
댓글 쓰기