⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readonlyrichtextbox.cs

📁 自定义控件
💻 CS
字号:
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

namespace ListViewEmbeddedControls
{
	/// <summary>
	/// Zusammenfassung f黵 ReadOnlyRichTextBox.
	/// </summary>
	public class ReadOnlyRichTextBox : RichTextBox
	{
		public ReadOnlyRichTextBox()
		{
			ReadOnly=true;
			TabStop=false;

			SetStyle(ControlStyles.Selectable, false);
		}

		// Font is overridden because assigning the RichTextBox to a new parent sets
		// its Font to the parent's Font and thus loses all formatting of existing RTF content.
		protected Font _font = new Font("Arial", 10);
		public override Font Font
		{
			get 
			{
				return _font;
			}
			set 
			{
				_font = value;
			}
		}

		[ Browsable(false) ]
		public new bool ReadOnly
		{
			get { return true; }
			set { }
		}
		
		[ Browsable(false) ]
		public new bool TabStop
		{
			get { return false; }
			set {  }
		}

		const int WM_SETFOCUS = 0x0007;
		protected override void WndProc(ref Message m)
		{
			switch (m.Msg)
			{
				case WM_SETFOCUS:
					// We don't want the RichTextBox to be able to receive focus, so just
					// pass the focus back to the control it came from.
					IntPtr prevCtl = m.WParam;
					Control c = Control.FromHandle(prevCtl);
					c.Select();
					return;
			}
			base.WndProc (ref m);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -