创建CustomRichTextBox.cs
class CustomRichTextBox : RichTextBox
{
[DllImport("user32.dll")]
static extern bool HideCaret(IntPtr hWnd);
private bool bReadOnly = false;
//隐藏光标
public void SetReadMode()
{
ReadOnly = true;
bReadOnly = true;
}
//显示光标
public void SetEditMode()
{
ReadOnly = false;
bReadOnly = false;
Focus();
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (bReadOnly)
HideCaret(Handle);
}
}
form.Designer.cs中修改
this.richTextBox = new CustomRichTextBox();
#endregion
private CustomRichTextBox articleform;
form.cs中添加
this.Cursor = Cursors.Arrow;
richTextBox.SetReadMode();
网友评论