첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainForm.cs

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요