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

為生存而奔跑

   :: 首頁 :: 聯系 :: 聚合  :: 管理
  271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

留言簿(5)

我參與的團隊

搜索

  •  

積分與排名

  • 積分 - 331751
  • 排名 - 74

最新評論

閱讀排行榜

評論排行榜

該控件可以作為一個簡易的代碼編輯器,可以實現代碼的高亮顯示,代碼行號等。

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>
        
/// 必需的設計器變量。
        
/// </summary>
        private System.ComponentModel.IContainer components = null;

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

        
#region 組件設計器生成的代碼

        
/// <summary>
        
/// 設計器支持所需的方法 - 不要
        
/// 使用代碼編輯器修改此方法的內容。
        
/// </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;
    }
}

現在程序還有bug: 假設“wang”是關鍵字,某一行的內容為:hellowang  wang,則本應該在第二個“wnag”上高亮顯示,但是結果在“hellowang”中的“wang”上高亮顯示了。
運行后界面如下:

posted on 2009-12-19 18:31 baby-fly 閱讀(389) 評論(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>
            亚洲国产精品久久久久| 欧美一区国产在线| 亚洲精品1区2区| 久久久综合视频| 一本久久a久久精品亚洲| 亚洲欧美国产一区二区三区| 蜜桃伊人久久| 国内精品免费在线观看| 久久精品国内一区二区三区| 欧美大片一区二区三区| 国产亚洲精品bt天堂精选| 野花国产精品入口| 亚洲曰本av电影| 夜色激情一区二区| 麻豆精品传媒视频| 黄色日韩网站| 麻豆视频一区二区| 欧美一区二区三区免费观看视频| 欧美色区777第一页| 一本久道综合久久精品| 最新国产拍偷乱拍精品| 欧美成人一区二区三区在线观看| 国产日产亚洲精品系列| 一区二区三区高清不卡| 一区二区三区精品在线| 国产精品狠色婷| 久久aⅴ国产欧美74aaa| 欧美成人自拍| 欧美系列精品| 久久亚洲欧美| 免费在线播放第一区高清av| 亚洲激情校园春色| 亚洲国产欧美日韩精品| 亚洲国产成人一区| 国产精品日韩一区二区三区| 久久精品二区亚洲w码| 久久亚洲国产精品日日av夜夜| 最新日韩欧美| 一区二区毛片| 久久综合网hezyo| 欧美日韩第一区| 久久久精品国产免大香伊| 欧美激情片在线观看| 一区二区三区免费看| 国产亚洲欧美一区二区| 亚洲一区久久久| 久久精品国产一区二区电影| 一本色道久久综合精品竹菊| 欧美在线视屏| 先锋影音久久久| 麻豆精品在线播放| 麻豆精品传媒视频| 国产综合色一区二区三区| 亚洲精品免费网站| 亚洲电影免费观看高清完整版在线观看| 国产麻豆视频精品| 亚洲国产精品一区二区第四页av| 国产日韩亚洲欧美综合| 一区二区三区精品| 亚洲色诱最新| 国产精品男女猛烈高潮激情 | 久久精品国产亚洲a| 亚洲第一天堂无码专区| 午夜一区在线| 久久久蜜桃一区二区人| 乱码第一页成人| 国产日韩欧美| 久久久久久久久久久久久9999 | 亚洲欧美在线高清| 久久久久久久久一区二区| 国产视频一区三区| 久久久久国产精品一区| 亚洲国产精品视频| 国产有码在线一区二区视频| 久久久久五月天| 亚洲精品日韩一| 亚洲精品在线观看免费| 欧美日韩精品在线| 亚洲一区欧美一区| 欧美高清视频一区二区三区在线观看| 亚洲狼人综合| 国产手机视频精品| 亚洲欧美综合网| 欧美激情bt| 久久成人一区二区| 99精品视频免费观看视频| 国产性天天综合网| 欧美日韩国产一区二区三区地区| 香蕉久久夜色精品| 亚洲亚洲精品三区日韩精品在线视频| 国产午夜精品久久久| 欧美日本高清一区| 免费日韩av电影| 噜噜噜躁狠狠躁狠狠精品视频 | 久久男人av资源网站| 一区二区三区高清| 亚洲国产精品美女| 免费一级欧美在线大片| 久久人91精品久久久久久不卡| 玖玖玖国产精品| 午夜精品一区二区三区在线| 亚洲免费电影在线| 正在播放日韩| 亚洲欧美日本伦理| 性做久久久久久| 欧美资源在线| 美女网站久久| 欧美午夜大胆人体| 欧美欧美午夜aⅴ在线观看| 欧美国产日韩xxxxx| 欧美日韩国产色视频| 欧美视频观看一区| 国产精品成人在线| 国产亚洲欧美另类一区二区三区| 国产区在线观看成人精品| 国产日产欧美一区| 最新国产の精品合集bt伙计| 国产精品日韩一区| 黄色一区三区| 亚洲桃花岛网站| 久久影院午夜论| 亚洲图片自拍偷拍| 久久亚洲综合网| 欧美视频中文一区二区三区在线观看| 国产性天天综合网| 亚洲男女自偷自拍| 欧美大尺度在线| 久久在线免费观看| 亚洲激情午夜| 亚洲精品乱码久久久久久久久 | 亚洲另类在线视频| 免费国产一区二区| 99国产精品久久久久久久成人热| 亚洲国产一区二区视频| 欧美日韩精品三区| 性亚洲最疯狂xxxx高清| 亚洲综合首页| 亚洲高清视频一区| 亚洲精品久久久久久久久久久| 欧美国产日韩精品免费观看| 久久久久国产一区二区三区| 亚洲国产日韩欧美在线图片| 欧美激情一区二区三区不卡| 欧美日韩国产成人在线| 欧美一级片一区| 久久一区亚洲| 欧美在线免费视屏| 蜜月aⅴ免费一区二区三区 | 亚洲天堂av在线免费| 中文在线不卡视频| 欧美高清视频一区二区| 亚洲线精品一区二区三区八戒| 欧美一级大片在线观看| 一区二区三区精品国产| 欧美一区二区在线播放| 一区二区三区精品国产| 久久视频国产精品免费视频在线| 亚洲伊人一本大道中文字幕| 久久亚洲综合| 欧美成人免费网| 狠狠狠色丁香婷婷综合久久五月| 一本大道久久精品懂色aⅴ| 玉米视频成人免费看| 欧美一区观看| 久久久夜夜夜| 在线观看91精品国产入口| 欧美一区午夜精品| 久久久欧美精品| 国产综合色产| 久久伊人免费视频| 亚洲国产精品999| 亚洲精品五月天| 欧美激情视频在线播放| 欧美激情国产精品| 一本久久a久久免费精品不卡| 免费成人高清| 亚洲美女免费精品视频在线观看| 一区二区欧美精品| 国产精品一区二区你懂的| 午夜一区二区三视频在线观看| 久久久国产亚洲精品| 在线观看福利一区| 久久婷婷蜜乳一本欲蜜臀| 亚洲国产精品一区二区第四页av | 久久久久久亚洲综合影院红桃 | 亚洲日韩视频| 国产精品成人一区| 久久久人成影片一区二区三区 | 亚洲美女av电影| 久久精品在线| 亚洲视频在线观看视频| 国一区二区在线观看| 欧美日韩精选| 美女视频黄免费的久久| 亚洲在线一区二区| 欧美国产第一页| 久久男人av资源网站| 亚洲欧美激情四射在线日| 亚洲精品五月天| 亚洲国产人成综合网站|