winform TextBox设置透明

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;
            }
        }

    }
}

  

原文地址:https://www.cnblogs.com/baozi789654/p/13619679.html