■ RichEditControl 클래스에서 코드로 프린터를 지정하고 문서를 인쇄하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" xmlns:dxre="http://schemas.devexpress.com/winfx/2008/xaml/richedit" Width="800" Height="600" Title="코드로 프린터 지정하고 문서 인쇄하기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <ResourceDictionary> <dxre:RichEditUICommand x:Key="RichEditUICommandKey" /> <dxre:RichEditStringIdConverter x:Key="RichEditStringIdConverterKey" /> <dxre:DefaultBarItemDataTemplates x:Key="DefaultBarItemDataTemplatesKey" /> </ResourceDictionary> </Window.Resources> <Grid> <dxb:BarManager x:Name="barManager" ToolbarGlyphSize="Small"> <dxb:BarManager.Items> <dxb:BarButtonItem x:Name="fileNewBarButtonItem" Command="{Binding Path=FileNew, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="fileOpenBarButtonItem" Command="{Binding Path=FileOpen, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="fileSaveBarButtonItem" Command="{Binding Path=FileSave, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="fileSaveAsBarButtonItem" Command="{Binding Path=FileSaveAs, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="fileQuickPrintBarButtonItem" Command="{Binding Path=FileQuickPrint, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="filePrintBarButtonItem" Command="{Binding Path=FilePrint, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="filePrintPreviewBarButtonItem" Command="{Binding Path=FilePrintPreview, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="editUndoBarButtonItem" Command="{Binding Path=EditUndo, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="editRedoBarButtonItem" Command="{Binding Path=EditRedo, Mode=OneTime, Source={StaticResource RichEditUICommandKey}}" /> <dxb:BarButtonItem x:Name="printToMyPrinterBarButtonItem" Content="PrintToMyPrinter" ItemClick="printToMyPrinterBarButtonItem_ItemClick" /> </dxb:BarManager.Items> <DockPanel> <dxr:RibbonControl x:Name="ribbonControl" DockPanel.Dock="Top"> <dxr:RibbonDefaultPageCategory> <dxr:RibbonPage x:Name="fileRibbonPage" Caption="{Binding Source={StaticResource RichEditStringIdConverterKey}, ConverterParameter=Caption_PageFile, Converter={StaticResource RichEditStringIdConverterKey}, Mode=OneTime}"> <dxr:RibbonPageGroup x:Name="fileCommonRibbonPageGroup" ShowCaptionButton="False" Caption="{Binding Source={StaticResource RichEditStringIdConverterKey}, ConverterParameter=Caption_GroupCommon, Converter={StaticResource RichEditStringIdConverterKey}, Mode=OneTime}"> <dxb:BarButtonItemLink BarItemName="fileNewBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="fileOpenBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="fileSaveBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="fileSaveAsBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="fileQuickPrintBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="filePrintBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="filePrintPreviewBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="editUndoBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="editRedoBarButtonItem" /> <dxb:BarButtonItemLink BarItemName="printToMyPrinterBarButtonItem" /> </dxr:RibbonPageGroup> </dxr:RibbonPage> </dxr:RibbonDefaultPageCategory> </dxr:RibbonControl> <dxre:RichEditControl x:Name="richEditControl" BarManager="{Binding ElementName=barManager, Mode=OneTime}" Ribbon="{Binding ElementName=ribbonControl, Mode=OneTime}" /> </DockPanel> </dxb:BarManager> </Grid> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
using System.Windows; using DevExpress.Xpf.Bars; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region PrintToMyPrinter 바 버튼 항목 항목 클릭시 처리하기 - printToMyPrinterBarButtonItem_ItemClick(sender, e) /// <summary> /// PrintToMyPrinter 바 버튼 항목 항목 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void printToMyPrinterBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) { new CustomXpfRichEditPrinter(this.richEditControl).PrintDocument(); } #endregion } } |