[TOOL/VS CODE] 파이썬 파일 편집시 선택한 범위의 소스 코드 주석 처리하기
■ 파이썬 파일 편집시 선택한 범위의 소스 코드를 주석으로 처리하는 방법을 보여준다. 1. 마우스 드래그나 SHIFT + 화살표 키를 눌러서 주석으로 처리할
■ 파이썬 파일 편집시 선택한 범위의 소스 코드를 주석으로 처리하는 방법을 보여준다. 1. 마우스 드래그나 SHIFT + 화살표 키를 눌러서 주석으로 처리할
■ 여러 줄 선택해서 편집하는 방법을 보여준다. 1. CTRL + ALT 키를 누른 상태에서 위아래 화살표 키를 눌러서 여러 줄을 선택한다. 2.
■ RichEditControl 클래스에서 테이블 셀의 내용을 복사해서 붙여넣는 방법을 보여준다. ▶ MainForm.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 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
using System; using System.Collections.Generic; using System.Drawing; using DevExpress.XtraEditors; using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 줄 문자열 /// </summary> private const string LINE_STRING = "----------------------------------------------------------------------------------------------------"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.richEditControl.ActiveViewType = RichEditViewType.Simple; this.richEditControl.Options.HorizontalScrollbar.Visibility = RichEditScrollbarVisibility.Hidden; this.richEditControl.Options.VerticalScrollbar.Visibility = RichEditScrollbarVisibility.Auto; this.richEditControl.Document.DefaultCharacterProperties.FontName = "나눔고딕코딩"; this.richEditControl.Document.DefaultCharacterProperties.FontSize = 12f; this.richEditControl.Document.DefaultCharacterProperties.ForeColor = Color.Black; this.richEditControl.Document.ParagraphStyles[0].FontName = "나눔고딕코딩"; this.richEditControl.Document.ParagraphStyles[0].FontSize = 12f; this.richEditControl.Document.ParagraphStyles[0].ForeColor = Color.Black; this.richEditControl.LoadDocument("sample.rtf"); this.parseButton.Click += parseButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 분석 버튼 클릭시 처리하기 - parseButton_Click(sender, e) /// <summary> /// 분석 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void parseButton_Click(object sender, EventArgs e) { Document document = this.richEditControl.Document; while(document.Tables.Count > 0) { PasteTableContent(document, document.Tables.Count - 1); document.Tables.RemoveTableAt(document.Tables.Count - 1); } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 라인 분리자 문단 리스트 구하기 - GetLineSeparatorParagraphList(document) /// <summary> /// 라인 분리자 문단 리스트 구하기 /// </summary> /// <param name="document">문서</param> /// <returns>라인 분리자 문단 리스트</returns> private List<Paragraph> GetLineSeparatorParagraphList(Document document) { List<Paragraph> list = new List<Paragraph>(); for(int i = 0; i < document.Paragraphs.Count - 1; i++) { Paragraph paragraph1 = document.Paragraphs[i ]; Paragraph paragraph2 = document.Paragraphs[i + 1]; string text1 = document.GetText(paragraph1.Range); string text2 = document.GetText(paragraph2.Range); if(text1 == LINE_STRING && text2 == LINE_STRING) { list.Add(paragraph1); } } return list; } #endregion #region 테이블 내용 붙여넣기 - PasteTableContent(document, index) /// <summary> /// 테이블 내용 붙여넣기 /// </summary> /// <param name="document">문서</param> /// <param name="index">인덱스</param> private void PasteTableContent(Document document, int index) { List<Paragraph> list = GetLineSeparatorParagraphList(document); Table table = document.Tables[index]; DocumentRange contentRange = table.Cell(0, 0).ContentRange; DocumentRange range = document.CreateRange(contentRange.Start.ToInt() + 1, contentRange.End.ToInt() - contentRange.Start.ToInt() + 1 - 2); document.Copy(range); document.CaretPosition = document.CreatePosition(list[index].Range.End.ToInt()); document.Paste(); } #endregion } } |
TestProject.zip
■ TableCollection 인터페이스 : Create 메소드를 사용해 테이블 생성하기 ▶ MainForm.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 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
using System; using System.Collections.Generic; using System.Drawing; using System.Text; using DevExpress.XtraEditors; using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 줄 문자열 /// </summary> private const string LINE_STRING = "------------------------------------------------------------------------------------------------------------------------"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.richEditControl.ActiveViewType = RichEditViewType.Simple; this.richEditControl.Options.HorizontalScrollbar.Visibility = RichEditScrollbarVisibility.Hidden; this.richEditControl.Options.VerticalScrollbar.Visibility = RichEditScrollbarVisibility.Auto; this.richEditControl.Document.DefaultCharacterProperties.FontName = "나눔고딕코딩"; this.richEditControl.Document.DefaultCharacterProperties.FontSize = 12f; this.richEditControl.Document.DefaultCharacterProperties.ForeColor = Color.Black; this.richEditControl.Document.ParagraphStyles[0].FontName = "나눔고딕코딩"; this.richEditControl.Document.ParagraphStyles[0].FontSize = 12f; this.richEditControl.Document.ParagraphStyles[0].ForeColor = Color.Black; this.richEditControl.LoadDocument("sample.rtf"); this.parseButton.Click += parseButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 분석 버튼 클릭시 처리하기 - parseButton_Click(sender, e) /// <summary> /// 분석 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void parseButton_Click(object sender, EventArgs e) { Document document = this.richEditControl.Document; StringBuilder stringBuilder = new StringBuilder(); Dictionary<Table, string> tableDictionary = new Dictionary<Table, string>(); foreach(Paragraph paragraph in document.Paragraphs) { ReadOnlyDocumentImageCollection imageCollection = document.Images.Get(paragraph.Range); if(imageCollection == null || imageCollection.Count == 0) { Table table = GetTable(paragraph.Range); if(table != null) { if(tableDictionary.ContainsKey(table)) { continue; } else { tableDictionary.Add(table, null); stringBuilder.AppendLine($"테이블 : {table.Rows.Count}×{table.Rows[0].Cells.Count}"); ParagraphCollection tableParagraphCollection = document.GetParagraphs(table.Range); foreach(Paragraph tableParagraph in tableParagraphCollection) { stringBuilder.AppendLine($" 문단 : {document.GetText(tableParagraph.Range)}"); } } } else { stringBuilder.AppendLine($"문단 : {document.GetText(paragraph.Range)}"); } } else { DocumentImage documentImage = imageCollection[0]; stringBuilder.AppendLine($"이미지 : {documentImage.Size}"); } } this.memoEdit.Text = stringBuilder.ToString(); document.BeginUpdate(); foreach(KeyValuePair<Table, string> keyValuePair in tableDictionary) { Table table = keyValuePair.Key; ParagraphCollection tableParagraphCollection = document.GetParagraphs(table.Range); Table newTable = document.Tables.Create(document.Range.End, 1, 1); for(int i = tableParagraphCollection.Count - 1; i > -1; i--) { Paragraph tableParagraph = tableParagraphCollection[i]; document.InsertText(newTable.Cell(0, 0).Range.Start, document.GetText(tableParagraph.Range) + (i < tableParagraphCollection.Count - 1 ? "\r\n" : "")); } document.InsertParagraph(document.Range.End); } document.EndUpdate(); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 테이블 구하기 - GetTable(range) /// <summary> /// 테이블 구하기 /// </summary> /// <param name="range">문서 범위</param> /// <returns>테이블</returns> private Table GetTable(DocumentRange range) { Document document = this.richEditControl.Document; foreach(Table table in document.Tables) { if(table.Range.Contains(range.Start)) { return table; } } return null; } #endregion } } |
TestProject.zip
■ RichEditControl 클래스에서 이미지와 문단/테이블을 파싱하는 방법을 보여준다. (기능 개선) ▶ MainForm.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 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
using System; using System.Collections.Generic; using System.Drawing; using System.Text; using DevExpress.XtraEditors; using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 줄 문자열 /// </summary> private const string LINE_STRING = "------------------------------------------------------------------------------------------------------------------------"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.richEditControl.ActiveViewType = RichEditViewType.Simple; this.richEditControl.Options.HorizontalScrollbar.Visibility = RichEditScrollbarVisibility.Hidden; this.richEditControl.Options.VerticalScrollbar.Visibility = RichEditScrollbarVisibility.Auto; this.richEditControl.Document.DefaultCharacterProperties.FontName = "나눔고딕코딩"; this.richEditControl.Document.DefaultCharacterProperties.FontSize = 12f; this.richEditControl.Document.DefaultCharacterProperties.ForeColor = Color.Black; this.richEditControl.Document.ParagraphStyles[0].FontName = "나눔고딕코딩"; this.richEditControl.Document.ParagraphStyles[0].FontSize = 12f; this.richEditControl.Document.ParagraphStyles[0].ForeColor = Color.Black; this.richEditControl.LoadDocument("sample.rtf"); this.parseButton.Click += parseButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 분석 버튼 클릭시 처리하기 - parseButton_Click(sender, e) /// <summary> /// 분석 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void parseButton_Click(object sender, EventArgs e) { Document document = this.richEditControl.Document; StringBuilder stringBuilder = new StringBuilder(); Dictionary<Table, string> tableDictionary = new Dictionary<Table, string>(); foreach(Paragraph paragraph in document.Paragraphs) { ReadOnlyDocumentImageCollection imageCollection = document.Images.Get(paragraph.Range); if(imageCollection == null || imageCollection.Count == 0) { Table table = GetTable(paragraph.Range); if(table != null) { if(tableDictionary.ContainsKey(table)) { continue; } else { tableDictionary.Add(table, null); stringBuilder.AppendLine($"테이블 : {table.Rows.Count}×{table.Rows[0].Cells.Count}"); ParagraphCollection tableParagraphCollection = document.GetParagraphs(table.Range); foreach(Paragraph tableParagraph in tableParagraphCollection) { stringBuilder.AppendLine($" 문단 : {document.GetText(tableParagraph.Range)}"); } } } else { stringBuilder.AppendLine($"문단 : {document.GetText(paragraph.Range)}"); } } else { DocumentImage documentImage = imageCollection[0]; stringBuilder.AppendLine($"이미지 : {documentImage.Size}"); } } this.memoEdit.Text = stringBuilder.ToString(); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 테이블 구하기 - GetTable(range) /// <summary> /// 테이블 구하기 /// </summary> /// <param name="range">문서 범위</param> /// <returns>테이블</returns> private Table GetTable(DocumentRange range) { Document document = this.richEditControl.Document; foreach(Table table in document.Tables) { if(table.Range.Contains(range.Start)) { return table; } } return null; } #endregion } } |
TestProject.zip
■ RichEditControl 클래스에서 특정 문자열을 포함하는 문단을 볼드체로 설정하는 방법을 보여준다. ▶ MainForm.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 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 |
using System.Collections.Generic; using System.Drawing; using DevExpress.XtraEditors; using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.richEditControl.ActiveViewType = RichEditViewType.Simple; this.richEditControl.Options.HorizontalScrollbar.Visibility = RichEditScrollbarVisibility.Hidden; this.richEditControl.Options.VerticalScrollbar.Visibility = RichEditScrollbarVisibility.Auto; this.richEditControl.Document.DefaultCharacterProperties.FontName = "나눔고딕코딩"; this.richEditControl.Document.DefaultCharacterProperties.FontSize = 12f; this.richEditControl.Document.DefaultCharacterProperties.ForeColor = Color.Black; this.richEditControl.Document.ParagraphStyles[0].FontName = "나눔고딕코딩"; this.richEditControl.Document.ParagraphStyles[0].FontSize = 12f; this.richEditControl.Document.ParagraphStyles[0].ForeColor = Color.Black; this.richEditControl.Document.InsertText(this.richEditControl.Document.Range.End, "가나다\r\n"); this.richEditControl.Document.InsertText(this.richEditControl.Document.Range.End, "라마바\r\n"); this.richEditControl.Document.InsertText(this.richEditControl.Document.Range.End, "사아자\r\n"); this.richEditControl.Document.InsertText(this.richEditControl.Document.Range.End, "차카타\r\n"); SetFontBold(this.richEditControl, new List<string> { "가", "자" }); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 폰트 볼드체 만들기 - SetFontBold(richEditControl, sourceList) /// <summary> /// 폰트 볼드체 만들기 /// </summary> /// <param name="richEditControl">리치 에디트 컨트롤</param> /// <param name="sourceList">소스 리스트</param> private void SetFontBold(RichEditControl richEditControl, List<string> sourceList) { if(sourceList == null || sourceList.Count == 0) { return; } Document document = richEditControl.Document; for(int i = 0; i < richEditControl.Document.Paragraphs.Count; i++) { DocumentRange documentRange = richEditControl.Document.Paragraphs[i].Range; string text = richEditControl.Document.GetText(documentRange); foreach(string source in sourceList) { if(text.Contains(source)) { CharacterProperties characterProperties = document.BeginUpdateCharacters(documentRange); characterProperties.Bold = true; document.EndUpdateCharacters(characterProperties); } } } } #endregion } } |
TestProject.zip
■ DocumentVisitorBase 클래스를 사용해 커스텀 문서 방문자를 만드는 방법을 보여준다. ▶ CustomVisitor.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 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 |
using System.Text; using DevExpress.XtraRichEdit.API.Native; namespace TestProject { /// <summary> /// 커스텀 방문자 /// </summary> public class CustomVisitor : DocumentVisitorBase { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 문자열 빌더 /// </summary> private readonly StringBuilder stringBuilder; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Private #region 텍스트 - Text /// <summary> /// 텍스트 /// </summary> public string Text { get { return this.stringBuilder.ToString(); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomVisitor() /// <summary> /// 생성자 /// </summary> public CustomVisitor() { this.stringBuilder = new StringBuilder(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 방문하기 - Visit(documentText) /// <summary> /// 방문하기 /// </summary> /// <param name="documentText">문서 텍스트</param> public override void Visit(DocumentText documentText) { string prefix = (documentText.TextProperties.FontBold) ? "**" : ""; this.stringBuilder.Append(prefix); this.stringBuilder.Append(documentText.Text); this.stringBuilder.Append(prefix); } #endregion #region 방문하기 - Visit(documentParagraphEnd) /// <summary> /// 방문하기 /// </summary> /// <param name="documentParagraphEnd">문서 문단 끝</param> public override void Visit(DocumentParagraphEnd documentParagraphEnd) { this.stringBuilder.AppendLine(); } #endregion } } |
▶ MainForm.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 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 |
using System; using System.Drawing; using DevExpress.XtraEditors; using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 줄 문자열 /// </summary> private const string LINE_STRING = "------------------------------------------------------------------------------------------------------------------------"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.richEditControl.ActiveViewType = RichEditViewType.Simple; this.richEditControl.Options.HorizontalScrollbar.Visibility = RichEditScrollbarVisibility.Hidden; this.richEditControl.Options.VerticalScrollbar.Visibility = RichEditScrollbarVisibility.Auto; this.richEditControl.Document.DefaultCharacterProperties.FontName = "나눔고딕코딩"; this.richEditControl.Document.DefaultCharacterProperties.FontSize = 12f; this.richEditControl.Document.DefaultCharacterProperties.ForeColor = Color.Black; this.richEditControl.Document.ParagraphStyles[0].FontName = "나눔고딕코딩"; this.richEditControl.Document.ParagraphStyles[0].FontSize = 12f; this.richEditControl.Document.ParagraphStyles[0].ForeColor = Color.Black; this.richEditControl.LoadDocument("sample.rtf"); this.parseButton.Click += parseButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 분석 버튼 클릭시 처리하기 - parseButton_Click(sender, e) /// <summary> /// 분석 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void parseButton_Click(object sender, EventArgs e) { CustomVisitor visitor = new CustomVisitor(); DocumentIterator iterator = new DocumentIterator(this.richEditControl.Document, true); while(iterator.MoveNext()) { iterator.Current.Accept(visitor); } this.memoEdit.Text = visitor.Text; } #endregion } } |
TestProject.zip
■ RichEditControl 클래스에서 이미지와 문단/테이블을 파싱하는 방법을 보여준다. ▶ MainForm.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 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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
using System; using System.Collections.Generic; using System.Drawing; using System.Text; using DevExpress.XtraEditors; using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 줄 문자열 /// </summary> private const string LINE_STRING = "------------------------------------------------------------------------------------------------------------------------"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.richEditControl.ActiveViewType = RichEditViewType.Simple; this.richEditControl.Options.HorizontalScrollbar.Visibility = RichEditScrollbarVisibility.Hidden; this.richEditControl.Options.VerticalScrollbar.Visibility = RichEditScrollbarVisibility.Auto; this.richEditControl.Document.DefaultCharacterProperties.FontName = "나눔고딕코딩"; this.richEditControl.Document.DefaultCharacterProperties.FontSize = 12f; this.richEditControl.Document.DefaultCharacterProperties.ForeColor = Color.Black; this.richEditControl.Document.ParagraphStyles[0].FontName = "나눔고딕코딩"; this.richEditControl.Document.ParagraphStyles[0].FontSize = 12f; this.richEditControl.Document.ParagraphStyles[0].ForeColor = Color.Black; this.richEditControl.LoadDocument("sample.rtf"); this.parseButton.Click += parseButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 분석 버튼 클릭시 처리하기 - parseButton_Click(sender, e) /// <summary> /// 분석 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void parseButton_Click(object sender, EventArgs e) { Document document = this.richEditControl.Document; Dictionary<Table, List<Paragraph>> tableDictionary = new Dictionary<Table, List<Paragraph>>(); Dictionary<Paragraph, Table> paragraphDictionary = new Dictionary<Paragraph, Table>(); foreach(Table table in document.Tables) { ParagraphCollection paragraphCollection = document.GetParagraphs(table.Range); List<Paragraph> paragraphList = new List<Paragraph>(); for(int i = 0; i < paragraphCollection.Count; i++) { Paragraph paragraph = paragraphCollection[i]; paragraphList.Add(paragraph); paragraphDictionary.Add(paragraph, table); } tableDictionary.Add(table, paragraphList); } List<object> targetList = new List<object>(); Dictionary<Table, string> targetTableDictionary = new Dictionary<Table, string>(); foreach(Paragraph paragraph in document.Paragraphs) { ReadOnlyDocumentImageCollection imageCollection = document.Images.Get(paragraph.Range); if(imageCollection == null || imageCollection.Count == 0) { if(paragraphDictionary.ContainsKey(paragraph)) { Table table = paragraphDictionary[paragraph]; if(!targetTableDictionary.ContainsKey(table)) { targetTableDictionary.Add(table, null); targetList.Add(table); } } else { targetList.Add(paragraph); } } else { DocumentImage documentImage = imageCollection[0]; targetList.Add(documentImage); } } StringBuilder stringBuilder = new StringBuilder(); foreach(var item in targetList) { if(item is Paragraph paragraph) { stringBuilder.AppendLine($"문단 : {document.GetText(paragraph.Range)}"); } else if(item is DocumentImage documentImage) { stringBuilder.AppendLine($"이미지 : {documentImage.Size}"); } else if(item is Table table) { stringBuilder.AppendLine($"테이블 : {table.Rows.Count}×{table.Rows[0].Cells.Count}"); } } this.memoEdit.Text = stringBuilder.ToString(); } #endregion } } |
TestProject.zip
■ RichEditControl 클래스에서 이미지와 문단을 파싱하는 방법을 보여준다. ▶ MainForm.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 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 |
using System; using System.Drawing; using System.Text; using DevExpress.XtraEditors; using DevExpress.XtraRichEdit; using DevExpress.XtraRichEdit.API.Native; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.richEditControl.ActiveViewType = RichEditViewType.Simple; this.richEditControl.Options.HorizontalScrollbar.Visibility = RichEditScrollbarVisibility.Hidden; this.richEditControl.Options.VerticalScrollbar.Visibility = RichEditScrollbarVisibility.Auto; this.richEditControl.Document.DefaultCharacterProperties.FontName = "나눔고딕코딩"; this.richEditControl.Document.DefaultCharacterProperties.FontSize = 12f; this.richEditControl.Document.DefaultCharacterProperties.ForeColor = Color.Black; this.richEditControl.Document.ParagraphStyles[0].FontName = "나눔고딕코딩"; this.richEditControl.Document.ParagraphStyles[0].FontSize = 12f; this.richEditControl.Document.ParagraphStyles[0].ForeColor = Color.Black; this.richEditControl.LoadDocument("sample.rtf"); this.parseButton.Click += parseButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 분석 버튼 클릭시 처리하기 - parseButton_Click(sender, e) /// <summary> /// 분석 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void parseButton_Click(object sender, EventArgs e) { Document document = this.richEditControl.Document; StringBuilder stringBuilder = new StringBuilder(); foreach(Paragraph paragraph in document.Paragraphs) { ReadOnlyDocumentImageCollection imageCollection = document.Images.Get(paragraph.Range); if(imageCollection == null || imageCollection.Count == 0) { stringBuilder.AppendLine($"문단 : {document.GetText(paragraph.Range)}"); } else { foreach(DocumentImage documentImage in imageCollection) { stringBuilder.AppendLine($"이미지 : {documentImage.Size}"); } } } this.memoEdit.Text = stringBuilder.ToString(); } #endregion } } |
TestProject.zip
■ MarkSymbolEditor 클래스를 사용해 마커 기호 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using Steema.TeeChart.Editors; using Steema.TeeChart.Styles; ... Bar bar; ... MarkSymbolEditor markSymbolEditor = new MarkSymbolEditor(bar.Marks.Symbol); EditorUtils.Translate(markSymbolEditor); EditorUtils.ShowFormModal(markSymbolEditor); |
■ CustomShapeEditor 클래스를 사용해 마커 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using Steema.TeeChart.Editors; using Steema.TeeChart.Styles; ... Bar bar; ... CustomShapeEditor customShapeEditor = new CustomShapeEditor(bar.Marks.Items[0]); EditorUtils.Translate(customShapeEditor); EditorUtils.ShowFormModal(customShapeEditor); |
■ ShadowEditor 클래스의 ShowDialog 메소드를 사용해 그림자 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
using System.Windows.Forms; using Steema.TeeChart; using Steema.TeeChart.Editors; ... private TChart tChart; ... ShadowEditor shadowEditor = new ShadowEditor(this.tChart.Panel.Shadow); shadowEditor.StartPosition = FormStartPosition.CenterParent; shadowEditor.ShowDialog(); |
■ ScrollBarEditor 클래스의 Edit 정적 메소드를 사용해 레전드 스크롤바 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 |
using Steema.TeeChart.Tools; ... LegendScrollBar legendScrollBar; ... ScrollBarEditor.Edit(legendScrollBar); |
■ LegendEditor 클래스를 사용해 레전드 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
using Steema.TeeChart; using Steema.TeeChart.Editors; private TChart tChart; ... LegendEditor legendEditor = new LegendEditor(this.tChart.Chart, null); EditorUtils.Translate(legendEditor); EditorUtils.ShowFormModal(legendEditor); |
■ SubChartEditor 클래스를 사용해 하위 차트 도구 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
using Steema.TeeChart.Editors; using Steema.TeeChart.Editors.Tools; using Steema.TeeChart.Tools; ... SubChartTool subChartTool; ... SubChartEditor subChartEditor = new SubChartEditor(subChartTool); EditorUtils.Translate(subChartEditor); EditorUtils.ShowFormModal(subChartEditor); |
■ SeriesBandToolEditor 클래스를 사용해 시리즈 밴드 도구 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
using Steema.TeeChart.Editors; using Steema.TeeChart.Editors.Tools; using Steema.TeeChart.Tools; ... SeriesBandTool seriesBandTool; ... SeriesBandToolEditor seriesBandToolEditor = new SeriesBandToolEditor(seriesBandTool); EditorUtils.Translate(seriesBandToolEditor); EditorUtils.ShowFormModal(seriesBandToolEditor); |
■ LightToolEditor 클래스를 사용해 조명 도구 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using Steema.TeeChart.Editors.Tools; using Steema.TeeChart.Tools; ... LightTool lightTool; ... LightToolEditor lightToolEditor = new LightToolEditor(lightTool); EditorUtils.Translate(lightToolEditor); EditorUtils.ShowFormModal(lightToolEditor); |
■ BrushEditor 클래스의 Edit 정적 메소드를 사용해 브러시 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
using Steema.TeeChart; using Steema.TeeChart.Editors; using Steema.TeeChart.Tools; private TChart tChart; ... GridBand gridBand = new GridBand(this.tChart.Chart); ... BrushEditor.Edit(gridBand.Band1, true); this.tChart.Invalidate(); |
■ ChartEditor 클래스의 ShowModal 메소드를 사용해 도구 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 |
using Steema.TeeChart; using Steema.TeeChart.Editors; private TChart tChart; ... ChartEditor.ShowModal(this.tChart.Chart, ChartEditorTabs.Tools); |
■ ToolsEditor 클래스의 ShowEditor 메소드를 사용해 도구 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 |
using Steema.TeeChart.Editors.Tools; using Steema.TeeChart.Tools; ... Annotation annotation; ... ToolsEditor.ShowEditor(annotation); |
■ Editor 클래스의 ShowModal 메소드를 사용해 축 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using Steema.TeeChart; using Steema.TeeChart.Editors; private TChart tChart; ... Editor editor = new Editor(this.tChart); editor.Title = "차트 에디터"; editor.DefaultTab = ChartEditorTabs.Axes; editor.ShowModal(); |
■ CustomShapeEditor 클래스를 사용해 축 레이블 항목 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
using Steema.TeeChart; using Steema.TeeChart.Editors; private TChart tChart; ... CustomShapeEditor customShapeEditor = new CustomShapeEditor(this.tChart.Axes.Left.Labels); EditorUtils.Translate(customShapeEditor); EditorUtils.ShowFormModal(customShapeEditor); |
■ CustomShapeEditor 클래스를 사용해 레이블 항목 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
using Steema.TeeChart; using Steema.TeeChart.Editors; private TChart tChart; ... CustomShapeEditor customShapeEditor = new CustomShapeEditor(this.tChart.Axes.Left.Labels.Items[0]); EditorUtils.Translate(customShapeEditor); EditorUtils.ShowFormModal(customShapeEditor); |
■ AxesEditor 클래스를 사용해 축 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
using Steema.TeeChart; using Steema.TeeChart.Editors; private TChart tChart; ... AxesEditor axesEditor = new AxesEditor(this.tChart.Chart, null); EditorUtils.Translate(axesEditor); EditorUtils.ShowFormModal(axesEditor); |
■ ShadowEditor 클래스를 사용해 그림자 속성을 편집하는 방법을 보여준다. ▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 |
using Steema.TeeChart.Editors; using Steema.TeeChart.Styles; Pie pie; ... ShadowEditor shadowEditor = new ShadowEditor(pie.Shadow, null); EditorUtils.Translate(shadowEditor); EditorUtils.ShowFormModal(shadowEditor); |