RichTextBox文字处理控件使用方法

1,实现右键功能

添加RichTextBox文字处理控件

private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)

{

System.Diagnostics.Process.Start(e.LinkText);

}

显示行号代码如下

private void 显示行号ToolStripMenuItem_Click(object sender, EventArgs e)

{

int n = 1; string data = "";

foreach (string s in richTextBox1.Lines)

{

data +=  n.ToString() + ":" + "  " + s + "\r\n";

n++;

}

richTextBox1.Text = data;

}

----------------------------------------------------------

private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)

{

try

{

this.Cursor = Cursors.WaitCursor;

string strTemp = richTextBox1.SelectedText;

//获取RichTextBox中选中的文字

if (strTemp.Equals("")) //判断是否为空

return;

Clipboard.Clear();//清除原有剪切板中内容

Clipboard.SetText(strTemp);//将文字添加到剪切板中,还添加Object类型数据

this.Cursor = Cursors.Default;

}

catch (System.Exception ex)

{

this.Cursor = Cursors.Default;

// CommonFunc.DisplayException(ex);

}

}

------------------------------------------------------------------

private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)

{

richTextBox1.Paste();

}

------------------------------------------------------------------

private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)

{

richTextBox1.Cut();

}

------------------------------------------------------------------

private void 红色ToolStripMenuItem1_Click(object sender, EventArgs e)

{

this.richTextBox1.ForeColor = System.Drawing.Color.Red;

}

private void 黄色ToolStripMenuItem1_Click(object sender, EventArgs e)

{

this.richTextBox1.ForeColor = System.Drawing.Color.Olive;

}

private void 蓝色ToolStripMenuItem1_Click(object sender, EventArgs e)

{

this.richTextBox1.ForeColor = System.Drawing.Color.Blue;

}

2,实现超链接

LinkClicked事件输入代码如下

private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)

{

System.Diagnostics.Process.Start(e.LinkText);

}

(0)

相关推荐