1,方法1:設置背景色與父容器的背景色一直
2,方法2:自定義控件,網上轉載的,我也不知道為什么這樣用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _009_TPS { class TransTextBox:RichTextBox//如果繼承TextBox,字體的顏色是黑色,改不了顏色 { [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)] static extern IntPtr LoadLibrary(string lpFileName); protected override CreateParams CreateParams { get { CreateParams prams = base.CreateParams; if (LoadLibrary("msftedit.dll") != IntPtr.Zero) { prams.ExStyle |= 0x020; prams.ClassName = "RICHEDIT50W"; } return prams; } } } }