chestnuts同志!我来做好事,你公布源码吧!

csharpsharper 2003-02-10 11:22:09
见上
...全文
20 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxj 2003-03-17
  • 打赏
  • 举报
回复
做的已经很好!
但是:
1、不区分关键词是否在字符串内的,每一种开发语言认为字符串都不一样
2、若关键词包含两个单词时:如:SQL 中的关键词 order by,
我输入ORDER BY (中间含有多个空格或者换行,就有问题)

chestnuts 2003-02-10
  • 打赏
  • 举报
回复
好!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication10
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private int bootIndex=0;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Panel panel2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//

}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.AutoSize = true;
this.richTextBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.RightMargin = 100;
this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedHorizontal;
this.richTextBox1.Size = new System.Drawing.Size(448, 308);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "well well";
this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(112, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 16);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(400, 248);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(16, 16);
this.panel1.TabIndex = 4;
this.panel1.Visible = false;
//
// label2
//
this.label2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(0)));
this.label2.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.label2.Location = new System.Drawing.Point(80, 240);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(296, 16);
this.label2.TabIndex = 5;
this.label2.Text = "the Key:\"me\",\"you\",\"and\",\"Lucy\",\"hehui\",\"heli\"";
//
// panel2
//
this.panel2.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.panel2.AutoScroll = true;
this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.richTextBox1});
this.panel2.Location = new System.Drawing.Point(0, 48);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(448, 308);
this.panel2.TabIndex = 6;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 358);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel2,
this.label2,
this.panel1,
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
this.richTextBox1.SaveFile("e:/12.rtf");
}

private void button2_Click(object sender, System.EventArgs e)
{
this.richTextBox1.SelectionColor=Color.Red;
}

private void richTextBox1_TextChanged(object sender, System.EventArgs e)
{
this.panel1.Select();
this.richTextBox1.HideSelection=true;
AllLines();
this.richTextBox1.Focus();
}

private void Form1_Load(object sender, System.EventArgs e)
{

}
private void AllLines()
{
String[] key={"me","you","and","Lucy","hehui","heli"};
bootIndex=this.richTextBox1.SelectionStart;
this.richTextBox1.SelectAll();
this.richTextBox1.SelectionColor=Color.Black;
this.richTextBox1.Select(bootIndex,0);
int length=this.richTextBox1.TextLength;
foreach(string keyword in key)
{
int start=this.richTextBox1.Find(keyword,RichTextBoxFinds.WholeWord|RichTextBoxFinds.NoHighlight);
while(start!=-1)
{
this.richTextBox1.Select(start,keyword.Length);
this.richTextBox1.SelectionColor=Color.Red;
this.richTextBox1.Select(start+keyword.Length,1);
this.richTextBox1.SelectionColor=Color.Black;
start=this.richTextBox1.Find(keyword,start+keyword.Length,RichTextBoxFinds.WholeWord|RichTextBoxFinds.NoHighlight);
if(start+keyword.Length>=length)//如果是最后打的的解决办法
{
this.richTextBox1.Select(start,keyword.Length);
this.richTextBox1.SelectionColor=Color.Red;
this.richTextBox1.Select(start+keyword.Length,0);
this.richTextBox1.SelectionColor=Color.Black;
break;
}

}
}
this.richTextBox1.Select(bootIndex,0);
}

}
}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧