青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

為生存而奔跑

   :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
  271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

留言簿(5)

我參與的團(tuán)隊(duì)

搜索

  •  

積分與排名

  • 積分 - 332291
  • 排名 - 74

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

該控件可以作為一個(gè)簡(jiǎn)易的代碼編輯器,可以實(shí)現(xiàn)代碼的高亮顯示,代碼行號(hào)等。

CodeRichText.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using HWND = System.IntPtr;

namespace CodeRichText
{
    public partial class CodeRichText : UserControl
    {
        private string[] keywords ={ };
        private string[] dividers ={ };

        public CodeRichText()
        {
            InitializeComponent();
            UpdateLineNo();
        }

        [DllImport("user32")]
        private static extern int SendMessage(HWND hwnd, int wMsg, int wParam, IntPtr lParam);
        private const int WM_SETREDRAW = 0xB;

        public string[] KeyWords
        {
            get { return keywords; }
            set 
            {
                keywords = value;
                ColorAllText();
            }
        }

        public string[] Dividers
        {
            get { return dividers; }
            set
            {
                dividers = value;
                ColorAllText();
            }
        }

        public string CodeText
        {
            get { return this.richTextBoxSourceCode.Text; }
            set { this.richTextBoxSourceCode.Text = value; }
        }

        public Font CodeFont
        {
            get { return this.richTextBoxSourceCode.Font; }
            set { this.richTextBoxSourceCode.Font = value; }
        }

        public void LoadFile(string path)
        {
            richTextBoxSourceCode.LoadFile(path,RichTextBoxStreamType.PlainText);
        }

        public void SaveFile(string path)
        {
            richTextBoxSourceCode.SaveFile(path,RichTextBoxStreamType.PlainText);
        }

        private void ColorAllText()
        {
            if (richTextBoxSourceCode.Text == string.Empty) return;
            for (int i = 0; i < richTextBoxSourceCode.Lines.Length;i++ )
                ColorCurrentText(i);
        }

        private void ColorCurrentText(int lineNum)
        {
            if (richTextBoxSourceCode.Text == string.Empty) return;

            string lineStr = richTextBoxSourceCode.Lines[lineNum];
            int selectStart = richTextBoxSourceCode.SelectionStart;
            int lineStart=0;
            for(int i=0;i<lineNum;i++)
                lineStart+=richTextBoxSourceCode.Lines[i].Length+1;

            SendMessage(richTextBoxSourceCode.Handle, WM_SETREDRAW, 0, IntPtr.Zero);

            richTextBoxSourceCode.SelectionStart = lineStart;
            richTextBoxSourceCode.SelectionLength = lineStr.Length;
            richTextBoxSourceCode.SelectionColor = Color.Black;
            richTextBoxSourceCode.SelectionStart = selectStart;
            richTextBoxSourceCode.SelectionLength = 0;
            richTextBoxSourceCode.SelectionColor = Color.Black;

            string[] words = lineStr.Split(dividers,StringSplitOptions.RemoveEmptyEntries);
            int lineIndex = 0;
            foreach (string word in words)
            {
                if (IsKeyWord(word))
                {
                    lineIndex = lineStr.IndexOf(word, lineIndex);
                    richTextBoxSourceCode.SelectionStart = lineStart + lineIndex;
                    richTextBoxSourceCode.SelectionLength = word.Length;
                    richTextBoxSourceCode.SelectionColor = Color.Blue;

                    richTextBoxSourceCode.SelectionStart = selectStart;
                    richTextBoxSourceCode.SelectionLength = 0;
                    richTextBoxSourceCode.SelectionColor = Color.Black;

                    lineIndex += word.Length + 1;
                }
                else if (IsNumber(word))
                {
                    lineIndex = lineStr.IndexOf(word, lineIndex);
                    richTextBoxSourceCode.SelectionStart = lineStart + lineIndex;
                    richTextBoxSourceCode.SelectionLength = word.Length;
                    richTextBoxSourceCode.SelectionColor = Color.Tomato;

                    richTextBoxSourceCode.SelectionStart = selectStart;
                    richTextBoxSourceCode.SelectionLength = 0;
                    richTextBoxSourceCode.SelectionColor = Color.Black;

                    lineIndex += word.Length + 1;
                }
            }

            SendMessage(richTextBoxSourceCode.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
            richTextBoxSourceCode.Refresh();
        }

        private bool IsKeyWord(string word)
        {
            foreach (string s in keywords)
            {
                if (string.Compare(word, s) == 0)
                    return true;
            }
            return false;
        }

        private bool IsNumber(string word)
        {
            foreach (char ch in word)
            {
                if (!(ch >= '0' && ch <= '9'))
                    return false;
            }
            return true;
        }

        private void richTextBoxSourceCode_TextChanged(object sender, EventArgs e)
        {
            if (richTextBoxSourceCode.Text == string.Empty) return;
            int lineNum = richTextBoxSourceCode.GetLineFromCharIndex(richTextBoxSourceCode.SelectionStart);
            UpdateLineNo();
            ColorCurrentText(lineNum);
        }

        private void UpdateLineNo()
        {
            SendMessage(richTextBoxLineNo.Handle, WM_SETREDRAW, 0, IntPtr.Zero);

            //get index of first visible char and number of first visible line
            Point pos = new Point(0, 0);
            int firstIndex = richTextBoxSourceCode.GetCharIndexFromPosition(pos);
            int firstLine = richTextBoxSourceCode.GetLineFromCharIndex(firstIndex);

            //get index of last visible char and number of last visible line
            pos.X = ClientRectangle.Width;
            pos.Y = ClientRectangle.Height;
            int lastIndex = richTextBoxSourceCode.GetCharIndexFromPosition(pos);
            int lastLine = richTextBoxSourceCode.GetLineFromCharIndex(lastIndex);

            //this is the point position of last visible char, use its Y value for calculating numberLabel size
            pos = richTextBoxSourceCode.GetPositionFromCharIndex(lastIndex);

            //finally, update line number
            StringBuilder lineNo = new StringBuilder();
            for (int i = firstLine; i <= lastLine + 1; i++)
            {
                lineNo.Append((i + 1).ToString() + "\n");
            }
            richTextBoxLineNo.Text = lineNo.ToString();

            SendMessage(richTextBoxLineNo.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
            richTextBoxLineNo.Refresh();
        }

        private void CodeRichText_Scroll(object sender, ScrollEventArgs e)
        {

        }

        private void richTextBoxSourceCode_VScroll(object sender, EventArgs e)
        {
            //move location of line number for amount of pixels caused by scrollbar
            int d = richTextBoxSourceCode.GetPositionFromCharIndex(0).Y % (richTextBoxSourceCode.Font.Height + 1);
            richTextBoxLineNo.Location = new Point(0, d);
            UpdateLineNo();
        }

        private void richTextBoxLineNo_Enter(object sender, EventArgs e)
        {
            richTextBoxSourceCode.Focus();
        }

        private void richTextBoxSourceCode_FontChanged(object sender, EventArgs e)
        {
            richTextBoxLineNo.Font = new Font(richTextBoxSourceCode.Font, FontStyle.Regular);
        }
    }
}

 
CodeRichText.Designer.cs

namespace CodeRichText
{
    partial 
class CodeRichText
    {
        
/// <summary>
        
/// 必需的設(shè)計(jì)器變量。
        
/// </summary>
        private System.ComponentModel.IContainer components = null;

        
/// <summary>
        
/// 清理所有正在使用的資源。
        
/// </summary>
        
/// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>
        protected override void Dispose(bool disposing)
        {
            
if (disposing && (components != null))
            {
                components.Dispose();
            }
            
base.Dispose(disposing);
        }

        
#region 組件設(shè)計(jì)器生成的代碼

        
/// <summary>
        
/// 設(shè)計(jì)器支持所需的方法 - 不要
        
/// 使用代碼編輯器修改此方法的內(nèi)容。
        
/// </summary>
        private void InitializeComponent()
        {
            
this.richTextBoxLineNo = new System.Windows.Forms.RichTextBox();
            
this.richTextBoxSourceCode = new System.Windows.Forms.RichTextBox();
            
this.SuspendLayout();
            
// 
            
// richTextBoxLineNo
            
// 
            this.richTextBoxLineNo.BackColor = System.Drawing.SystemColors.ControlLight;
            
this.richTextBoxLineNo.BorderStyle = System.Windows.Forms.BorderStyle.None;
            
this.richTextBoxLineNo.Cursor = System.Windows.Forms.Cursors.Arrow;
            
this.richTextBoxLineNo.Dock = System.Windows.Forms.DockStyle.Left;
            
this.richTextBoxLineNo.Font = new System.Drawing.Font("Courier New", 10F);
            
this.richTextBoxLineNo.ForeColor = System.Drawing.SystemColors.GradientActiveCaption;
            
this.richTextBoxLineNo.Location = new System.Drawing.Point(00);
            
this.richTextBoxLineNo.Name = "richTextBoxLineNo";
            
this.richTextBoxLineNo.ReadOnly = true;
            
this.richTextBoxLineNo.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
            
this.richTextBoxLineNo.Size = new System.Drawing.Size(41408);
            
this.richTextBoxLineNo.TabIndex = 1;
            
this.richTextBoxLineNo.Text = "";
            
this.richTextBoxLineNo.Enter += new System.EventHandler(this.richTextBoxLineNo_Enter);
            
// 
            
// richTextBoxSourceCode
            
// 
            this.richTextBoxSourceCode.BorderStyle = System.Windows.Forms.BorderStyle.None;
            
this.richTextBoxSourceCode.Dock = System.Windows.Forms.DockStyle.Fill;
            
this.richTextBoxSourceCode.Font = new System.Drawing.Font("Courier New", 10F);
            
this.richTextBoxSourceCode.Location = new System.Drawing.Point(410);
            
this.richTextBoxSourceCode.Name = "richTextBoxSourceCode";
            
this.richTextBoxSourceCode.Size = new System.Drawing.Size(639408);
            
this.richTextBoxSourceCode.TabIndex = 0;
            
this.richTextBoxSourceCode.Text = "";
            
this.richTextBoxSourceCode.VScroll += new System.EventHandler(this.richTextBoxSourceCode_VScroll);
            
this.richTextBoxSourceCode.TextChanged += new System.EventHandler(this.richTextBoxSourceCode_TextChanged);
            
// 
            
// CodeRichText
            
// 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            
this.Controls.Add(this.richTextBoxSourceCode);
            
this.Controls.Add(this.richTextBoxLineNo);
            
this.Name = "CodeRichText";
            
this.Size = new System.Drawing.Size(680408);
            
this.Scroll += new System.Windows.Forms.ScrollEventHandler(this.CodeRichText_Scroll);
            
this.ResumeLayout(false);

        }

        
#endregion

        
private System.Windows.Forms.RichTextBox richTextBoxLineNo;
        
private System.Windows.Forms.RichTextBox richTextBoxSourceCode;
    }
}

現(xiàn)在程序還有bug: 假設(shè)“wang”是關(guān)鍵字,某一行的內(nèi)容為:hellowang  wang,則本應(yīng)該在第二個(gè)“wnag”上高亮顯示,但是結(jié)果在“hellowang”中的“wang”上高亮顯示了。
運(yùn)行后界面如下:

posted on 2009-12-19 18:31 baby-fly 閱讀(390) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C#
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美大片免费久久精品三p| 欧美另类极品videosbest最新版本| 亚洲午夜一级| 在线亚洲高清视频| 亚洲夜间福利| 亚洲在线免费视频| 亚洲综合精品四区| 午夜精品成人在线视频| 欧美亚洲视频在线观看| 午夜精品www| 久久精品在线观看| 久久视频一区| 欧美第一黄色网| 欧美日韩99| 国产精品久久久爽爽爽麻豆色哟哟 | 国产日韩欧美三区| 国产亚洲欧美日韩一区二区| 一区二区视频免费完整版观看| 尤物在线观看一区| 99国产精品视频免费观看一公开| 一本一本久久a久久精品综合麻豆| 一区二区三区精品在线| 午夜精品一区二区三区在线| 久久精品青青大伊人av| 欧美成人69av| 日韩视频免费看| 亚洲欧美日韩综合国产aⅴ| 久久国产乱子精品免费女| 久热精品视频| 欧美日在线观看| 国产一区亚洲| 日韩视频在线一区二区三区| 亚洲私人影院在线观看| 久久久九九九九| 亚洲国产99| 亚洲一区二区视频在线| 久久国产精品久久国产精品| 欧美成人资源网| 国产精品永久免费在线| 亚洲大片一区二区三区| 亚洲性线免费观看视频成熟| 久久久五月婷婷| 亚洲久久一区| 久久精品二区亚洲w码| 欧美极品在线观看| 国产亚洲欧美激情| av成人激情| 久久一区免费| 亚洲午夜精品久久| 欧美成人免费视频| 国产一区激情| 亚洲一区二区在线播放| 欧美本精品男人aⅴ天堂| 夜夜嗨av色一区二区不卡| 久久人人看视频| 国产精品毛片在线看| 亚洲黄色在线看| 欧美一级精品大片| 亚洲激情午夜| 久久九九热免费视频| 国产精品欧美日韩一区二区| 亚洲精品美女| 久久天堂av综合合色| 亚洲视频免费在线观看| 欧美激情区在线播放| 亚洲国产精品一区| 久久色在线观看| 亚洲欧美成人精品| 欧美视频在线一区二区三区| 亚洲国产一成人久久精品| 久久精品1区| 中文av一区二区| 欧美久久久久免费| 亚洲国产高清在线| 久久婷婷国产综合尤物精品| 亚洲网站在线播放| 欧美另类videos死尸| 亚洲经典自拍| 久久综合一区二区| 午夜精品www| 国产精品久久久久久av福利软件| 日韩香蕉视频| 亚洲国产综合在线| 美国三级日本三级久久99| 好吊日精品视频| 久久九九99视频| 先锋影音网一区二区| 国产精品美腿一区在线看| 一区二区三区四区五区视频 | 另类综合日韩欧美亚洲| 亚洲综合第一| 国产美女诱惑一区二区| 性一交一乱一区二区洋洋av| 亚洲一区不卡| 国产精品美女久久久久aⅴ国产馆| 亚洲网站啪啪| aaa亚洲精品一二三区| 欧美精品一级| 亚洲最新在线视频| 亚洲精品视频中文字幕| 欧美日韩国产精品一区| 正在播放欧美一区| 亚洲蜜桃精久久久久久久| 欧美日韩国产综合一区二区| 亚洲天堂av在线免费| 亚洲网站在线观看| 国产欧美一区二区精品忘忧草| 欧美一级午夜免费电影| 欧美一区三区三区高中清蜜桃| 国产亚洲一区二区三区在线播放| 久久久www成人免费毛片麻豆| 亚洲欧美日韩在线高清直播| 国产综合亚洲精品一区二| 久久亚洲一区二区| 免费日韩一区二区| 99视频热这里只有精品免费| 一本一道久久综合狠狠老精东影业 | 性色av一区二区三区在线观看| 亚洲欧美文学| 亚洲成人在线免费| 亚洲精品乱码久久久久久按摩观 | 99re国产精品| 9l国产精品久久久久麻豆| 国产精品日韩欧美一区二区三区| 欧美一区二区三区久久精品| 久久精品国产v日韩v亚洲| 亚洲国产高清一区二区三区| 亚洲乱亚洲高清| 国产人久久人人人人爽| 欧美jizz19性欧美| 欧美视频一区二| 久久久www成人免费毛片麻豆| 久久天堂精品| 一区二区三区不卡视频在线观看| 亚洲欧美成人在线| 亚洲电影专区| 99国产精品久久久| 国产一区二区三区久久精品| 欧美激情第五页| 国产精品久久久91| 久久综合伊人| 欧美三级在线视频| 毛片av中文字幕一区二区| 欧美日韩日日夜夜| 久久亚洲高清| 欧美性jizz18性欧美| 久久另类ts人妖一区二区| 欧美激情免费在线| 久久激五月天综合精品| 欧美黑人一区二区三区| 欧美一区二区三区日韩视频| 麻豆91精品91久久久的内涵| 亚洲综合二区| 免费欧美日韩| 亚洲欧美激情视频| 毛片一区二区三区| 久久riav二区三区| 欧美女人交a| 麻豆精品视频| 国产精品无码永久免费888| 亚洲二区在线观看| 国模精品娜娜一二三区| 中文在线资源观看视频网站免费不卡| 精久久久久久久久久久| 亚洲一区三区电影在线观看| 亚洲精品日韩综合观看成人91| 亚洲淫性视频| 一本色道久久| 免费在线观看精品| 久久尤物视频| 国产日产精品一区二区三区四区的观看方式 | 亚洲少妇一区| 亚洲精品自在在线观看| 久久久久久穴| 久久精品国产综合| 国产精品入口夜色视频大尺度| 亚洲国产欧美一区| 在线播放一区| 久久av二区| 久久国产精品毛片| 国产精品久久久久毛片软件| 亚洲日本欧美日韩高观看| 亚洲国产高清视频| 久久久久久久一区二区| 久久国产精品久久久久久电车| 国产精品国产一区二区| 亚洲精品一区久久久久久| 亚洲欧洲精品一区二区精品久久久| 欧美在线免费观看视频| 欧美一区二区三区四区在线| 欧美视频手机在线| 亚洲最新在线| 宅男66日本亚洲欧美视频| 欧美另类人妖| 亚洲茄子视频| 99精品热6080yy久久| 欧美猛交免费看| 日韩一区二区免费高清| 一区二区三区国产在线| 欧美精品一二三|