就像标题一样:我在网上搜索了答案,但我无法找到隐藏VB.NET中RichTextBox插入符号的方法.
我试图将RichTextBox.Enabled属性设置为False,然后将背景颜色和前景颜色更改为非灰色,但这并不能解决问题.
提前致谢.
解:
来自:http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_21896403.html
using System; using System.Windows.Forms; using System.ComponentModel; using System.Runtime.InteropServices; public class ReadOnlyRichTextBox : System.Windows.Forms.RichTextBox { [DllImport("user32.dll")] private static extern int HideCaret (IntPtr hwnd); public ReadOnlyRichTextBox() { this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ReadOnlyRichTextBox_Mouse); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ReadOnlyRichTextBox_Mouse); base.ReadOnly = true; base.TabStop = false; HideCaret(this.Handle); } protected override void OnGotFocus(EventArgs e) { HideCaret(this.Handle); } protected override void OnEnter(EventArgs e) { HideCaret(this.Handle); } [DefaultValue(true)] public new bool ReadOnly { get { return true; } set { } } [DefaultValue(false)] public new bool TabStop { get { return false; } set { } } private void ReadOnlyRichTextBox_Mouse(object sender, System.Windows.Forms.MouseEventArgs e) { HideCaret(this.Handle); } private void InitializeComponent() { // // ReadOnlyRichTextBox // this.Resize += new System.EventHandler(this.ReadOnlyRichTextBox_Resize); } private void ReadOnlyRichTextBox_Resize(object sender, System.EventArgs e) { HideCaret(this.Handle); } }