728x90
반응형
728x170
▶ MainWindow.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
Width = 800;
Height = 600;
Title = "ToolBar 클래스 사용하기";
FontFamily = new FontFamily("나눔고딕코딩");
FontSize = 16;
RoutedUICommand[] routedUICommandArray =
{
ApplicationCommands.New ,
ApplicationCommands.Open ,
ApplicationCommands.Save ,
ApplicationCommands.Print,
ApplicationCommands.Cut ,
ApplicationCommands.Copy ,
ApplicationCommands.Paste,
ApplicationCommands.Delete
};
string[] imageNameArray =
{
"NewDocumentHS.png",
"openHS.png" ,
"saveHS.png" ,
"PrintHS.png" ,
"CutHS.png" ,
"CopyHS.png" ,
"PasteHS.png" ,
"DeleteHS.png"
};
DockPanel dockPanel = new DockPanel();
Content = dockPanel;
ToolBar toolBar = new ToolBar();
dockPanel.Children.Add(toolBar);
DockPanel.SetDock(toolBar, Dock.Top);
for(int i = 0; i < 8; i++)
{
if(i == 4)
{
toolBar.Items.Add(new Separator());
}
Button button = new Button();
button.Command = routedUICommandArray[i];
toolBar.Items.Add(button);
Image image = new Image();
image.Source = new BitmapImage(new Uri("pack://application:,,,/IMAGE/" + imageNameArray[i]));
image.Stretch = Stretch.None;
StackPanel stackPanel = new StackPanel();
stackPanel.Orientation = Orientation.Horizontal;
button.Content = stackPanel;
TextBlock textBlock = new TextBlock();
textBlock.Text = routedUICommandArray[i].Text;
stackPanel.Children.Add(image);
stackPanel.Children.Add(textBlock);
ToolTip toolTip = new ToolTip();
toolTip.Content = routedUICommandArray[i].Text;
button.ToolTip = toolTip;
CommandBindings.Add(new CommandBinding(routedUICommandArray[i], ToolBarButtonExecuted));
}
RichTextBox richTextBox = new RichTextBox();
dockPanel.Children.Add(richTextBox);
richTextBox.Focus();
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
[STAThread]
public static void Main()
{
Application application = new Application();
application.Run(new MainWindow());
}
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Instance
//////////////////////////////////////////////////////////////////////////////// Private
#region 툴바 버튼 실행시 처리하기 - ToolBarButtonExecuted(sender, e)
/// <summary>
/// 툴바 버튼 실행시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void ToolBarButtonExecuted(object sender, ExecutedRoutedEventArgs e)
{
RoutedUICommand routedUICommand = e.Command as RoutedUICommand;
MessageBox.Show(routedUICommand.Name + " command not yet implemented", Title);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] 의존 속성 탐색하기 (0) | 2018.03.24 |
---|---|
[C#/WPF] 시스템 매개 변수 조회하기 (0) | 2018.03.24 |
[C#/WPF] 클래스 계층도 표시하기 (0) | 2018.03.24 |
[C#/WPF] TreeView 클래스 사용하기 (0) | 2018.03.24 |
[C#/WPF] ToolBarTray 클래스 사용하기 (0) | 2018.03.24 |
[C#/WPF] ToolBar 클래스 사용하기 (0) | 2018.03.24 |
[C#/WPF] ContextMenu 클래스 : 컨텍스트 메뉴 표시하기 (0) | 2018.03.24 |
[C#/WPF] RoutedUICommand 클래스 : 메뉴 명령 실행하기 (0) | 2018.03.22 |
[C#/WPF] 잘라내기, 복사하기, 그리고 붙여넣기 (0) | 2018.03.21 |
[C#/WPF] Menu 클래스 : 색상 그리드 박스 메뉴에서 색상 선택하기 (0) | 2018.03.18 |
[C#/WPF] Menu 클래스 : 색상 선택하기 (0) | 2018.03.18 |
댓글을 달아 주세요