첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
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"
    xmlns:dxre="http://schemas.devexpress.com/winfx/2008/xaml/richedit"
    Width="800"
    Height="600"
    Title="선택 텍스트 포맷 변경하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*"    />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0">
            <Button x:Name="formatCharactersButton"
                Margin="10"
                Height="25"
                Content="Format Characters"
                Click="formatCharactersButton_Click" />
            <Button x:Name="formatParagraphButton"
                Margin="10"
                Height="25"
                Content="Format Paragraph"
                Click="formatParagraphButton_Click" />
        </StackPanel>
        <dxre:RichEditControl x:Name="richEditControl" Grid.Column="1" />
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Drawing;
using System.Windows;

using DevExpress.Office.Utils;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

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

        #region 생성자 - MainWindow()

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

            this.richEditControl.Document.LoadDocument("SampleText.rtf", DocumentFormat.Rtf);
        }

        #endregion

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

        #region Format Characters 버튼 클릭시 처리하기 - formatCharactersButton_Click(sender, e)

        /// <summary>
        /// Format Characters 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void formatCharactersButton_Click(object sender, RoutedEventArgs e)
        {
            Document            document            = this.richEditControl.Document;
            DocumentRange       documentRange       = document.Selection;
            CharacterProperties characterProperties = document.BeginUpdateCharacters(documentRange);

            characterProperties.FontName       = "Comic Sans MS";
            characterProperties.FontSize       = 18;
            characterProperties.ForeColor      = Color.Yellow;
            characterProperties.BackColor      = Color.Blue;
            characterProperties.Underline      = UnderlineType.DoubleWave;
            characterProperties.UnderlineColor = Color.White;

            document.EndUpdateCharacters(characterProperties);
        }

        #endregion
        #region Format Paragraph 버튼 클릭시 처리하기 - formatParagraphButton_Click(sender, e)

        /// <summary>
        /// Format Paragraph 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void formatParagraphButton_Click(object sender, RoutedEventArgs e)
        {
            Document            document            = this.richEditControl.Document;            
            DocumentRange       documentRange       = document.Selection;
            ParagraphProperties paragraphProperties = document.BeginUpdateParagraphs(documentRange);

            paragraphProperties.Alignment             = ParagraphAlignment.Center;
            paragraphProperties.LineSpacingType       = ParagraphLineSpacing.Multiple;
            paragraphProperties.LineSpacingMultiplier = 3;
            paragraphProperties.LeftIndent            = Units.InchesToDocumentsF(0.5f);

            TabInfoCollection tabInfoCollection = paragraphProperties.BeginUpdateTabs(true);
            TabInfo           tabInfo           = new TabInfo();

            tabInfo.Alignment = TabAlignmentType.Center;
            tabInfo.Position  = Units.InchesToDocumentsF(1.5f);

            tabInfoCollection.Add(tabInfo);

            paragraphProperties.EndUpdateTabs(tabInfoCollection);

            document.EndUpdateParagraphs(paragraphProperties);
        }

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

댓글을 달아 주세요