textbox滚动条(RichTextBox富文本输入框禁止编辑输入)
1、设置richTextBox1.Enabled = false;
此时整个输入框被禁止使用,界面会变成灰色,滚动条不能拖动,不美观也不满足要求。如图所示:
2、用KeyDown和KeyPress事件来控制
在keydown和keypress事件中输入"e.Handled = true;"即可。此时整个输入框样式保持不变,只是禁止了输入。如图所示:
完整代码如下:
public partial class Form6 : Form { public Form6() { InitializeComponent(); } private void Form6_Load(object sender, EventArgs e) { richTextBox1.Enabled = false; richTextBox2.KeyDown += richTextBox2_KeyDown; richTextBox2.KeyPress += richTextBox2_KeyPress; } #region 禁止输入 /// <summary> /// 键按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void richTextBox2_KeyPress(object sender, KeyPressEventArgs e) { //标识事件已被处理 e.Handled = true; } /// <summary> /// 键按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void richTextBox2_KeyDown(object sender, KeyEventArgs e) { e.Handled = true; } #endregion }