Click here to Skip to main content
15,893,161 members
Articles / Programming Languages / C#

Regular Expressions Syntax Highlighting

Rate me:
Please Sign up or sign in to vote.
4.34/5 (17 votes)
7 Sep 2008CPOL3 min read 40.5K   1K   43  
Easy to use syntax highlighting class
namespace tevton.SyntaxHighlightDemo {
    partial class Form1 {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing) {
            if(disposing && (components != null)) {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            this.btnHighlight = new System.Windows.Forms.Button();
            this.chbAutoHighlight = new System.Windows.Forms.CheckBox();
            this.synBox1 = new System.Windows.Forms.RichTextBox();
            this.SuspendLayout();
            // 
            // btnHighlight
            // 
            this.btnHighlight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnHighlight.Location = new System.Drawing.Point(470, 329);
            this.btnHighlight.Name = "btnHighlight";
            this.btnHighlight.Size = new System.Drawing.Size(75, 24);
            this.btnHighlight.TabIndex = 2;
            this.btnHighlight.Text = "Highlight";
            this.btnHighlight.UseVisualStyleBackColor = true;
            this.btnHighlight.Click += new System.EventHandler(this.btnHighlight_Click);
            // 
            // chbAutoHighlight
            // 
            this.chbAutoHighlight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.chbAutoHighlight.AutoSize = true;
            this.chbAutoHighlight.Location = new System.Drawing.Point(13, 334);
            this.chbAutoHighlight.Name = "chbAutoHighlight";
            this.chbAutoHighlight.Size = new System.Drawing.Size(129, 17);
            this.chbAutoHighlight.TabIndex = 1;
            this.chbAutoHighlight.Text = "Automatic highlighting";
            this.chbAutoHighlight.UseVisualStyleBackColor = true;
            this.chbAutoHighlight.CheckedChanged += new System.EventHandler(this.chbAutoHighlight_CheckedChanged);
            // 
            // synBox1
            // 
            this.synBox1.AcceptsTab = true;
            this.synBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.synBox1.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
            this.synBox1.Location = new System.Drawing.Point(12, 12);
            this.synBox1.Name = "synBox1";
            this.synBox1.Size = new System.Drawing.Size(533, 302);
            this.synBox1.TabIndex = 0;
            this.synBox1.Text = "/*Multiline comments\nwith \'string\' and keyword SELECT inside\n*/\nSELECT price --ke" +
                "yword highlighted\nFROM titles\nWHERE type = \'business\' /*string highlighted*/";
            this.synBox1.WordWrap = false;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(557, 364);
            this.Controls.Add(this.synBox1);
            this.Controls.Add(this.chbAutoHighlight);
            this.Controls.Add(this.btnHighlight);
            this.Name = "Form1";
            this.Text = "Syntax highlight demo";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button btnHighlight;
        private System.Windows.Forms.CheckBox chbAutoHighlight;
        private System.Windows.Forms.RichTextBox synBox1;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions