如何在c#中为richtextbox设置透明背景颜色

时间:2014-09-20 11:49:43

标签: c# transparent

我想将richtextbox的背景颜色设置为透明在c#中 你能帮我吗 它是一个winform应用程序

1 个答案:

答案 0 :(得分:11)

    public class TransparentLabel : RichTextBox
    {
        public TransparentLabel()
        {
            this.SetStyle(ControlStyles.Opaque, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
            this.TextChanged += TransparentLabel_TextChanged;
            this.VScroll += TransparentLabel_TextChanged;
            this.HScroll += TransparentLabel_TextChanged;
        }

        void TransparentLabel_TextChanged(object sender, System.EventArgs e)
        {
            this.ForceRefresh();
        }
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams parms = base.CreateParams;
                parms.ExStyle |= 0x20;  // Turn on WS_EX_TRANSPARENT
                return parms;
            }
        }
        public void ForceRefresh()
        {
            this.UpdateStyles();
        }
    }

,答案如下: enter image description here