■ Scintilla 클래스에서 C# 구문 하이라이트를 사용하는 방법을 보여준다.
▶ 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 178 179 180 181 182 183 184 185 186 187 188 189 190 |
using System.Drawing; using System.Text; using System.Windows.Forms; using ScintillaNET; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 키워드 배열 1 /// </summary> private string[] keywordArray1 = new string[] { "abstract", "as", "base", "break", "case", "catch", "checked", "continue", "default", "delegate", "do", "else", "event", "explicit", "extern", "false", "finally", "fixed", "for", "foreach", "goto", "if", "implicit", "in", "interface", "internal", "is", "lock", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sealed", "sizeof", "stackalloc", "switch", "this", "throw", "true", "try", "typeof", "unchecked", "unsafe", "using", "virtual", "while" }; /// <summary> /// 키워드 배열 2 /// </summary> private string[] keywordArray2 = new string[] { "bool", "byte", "char", "class", "const", "decimal", "double", "enum", "float", "int", "long", "sbyte", "short", "static", "string", "struct", "uint", "ulong", "ushort", "void" }; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.scintilla.Margins[0].Type = MarginType.Number; this.scintilla.Margins[0].Width = 35; this.scintilla.StyleResetDefault(); this.scintilla.Styles[Style.Default].Font = "나눔고딕코딩"; this.scintilla.Styles[Style.Default].Size = 12; this.scintilla.StyleClearAll(); this.scintilla.Styles[Style.Cpp.Default ].ForeColor = Color.Silver; this.scintilla.Styles[Style.Cpp.Comment ].ForeColor = Color.FromArgb(0 , 128, 0 ); this.scintilla.Styles[Style.Cpp.CommentLine ].ForeColor = Color.FromArgb(0 , 128, 0 ); this.scintilla.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); this.scintilla.Styles[Style.Cpp.Number ].ForeColor = Color.Olive; this.scintilla.Styles[Style.Cpp.Word ].ForeColor = Color.Blue; this.scintilla.Styles[Style.Cpp.Word2 ].ForeColor = Color.Blue; this.scintilla.Styles[Style.Cpp.String ].ForeColor = Color.FromArgb(163, 21, 21); this.scintilla.Styles[Style.Cpp.Character ].ForeColor = Color.FromArgb(163, 21, 21); this.scintilla.Styles[Style.Cpp.Verbatim ].ForeColor = Color.FromArgb(163, 21, 21); this.scintilla.Styles[Style.Cpp.StringEol ].BackColor = Color.Pink; this.scintilla.Styles[Style.Cpp.Operator ].ForeColor = Color.Purple; this.scintilla.Styles[Style.Cpp.Preprocessor ].ForeColor = Color.Maroon; this.scintilla.Lexer = Lexer.Cpp; this.scintilla.SetKeywords(0, ConnectString(this.keywordArray1, " ")); this.scintilla.SetKeywords(1, ConnectString(this.keywordArray2, " ")); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 문자열 연결하기 - ConnectString(sourceArray, link) /// <summary> /// 문자열 연결하기 /// </summary> /// <param name="sourceArray">소스 문자열 배열</param> /// <param name="link">연결 문자열</param> /// <returns>연결 문자열</returns> private string ConnectString(string[] sourceArray, string link) { StringBuilder stringBuilder = new StringBuilder(); for(int i = 0; i < sourceArray.Length; i++) { if(sourceArray[i].Length > 0) { if(stringBuilder.Length > 0) { stringBuilder.Append(link); } stringBuilder.Append(sourceArray[i]); } } return stringBuilder.ToString(); } #endregion } } |