zoukankan      html  css  js  c++  java
  • .net控件Control透明

    public partial class tspControl : UserControl
        {
            public tspControl()
            {
                InitializeComponent();
                SetStyle(ControlStyles.SupportsTransparentBackColor
                  | ControlStyles.UserPaint
                  | ControlStyles.AllPaintingInWmPaint
                  | ControlStyles.Opaque, true);
                this.BackColor = Color.Transparent;
            }       
            private Image img;
            public Image Image
            {
                get
                {
                    return img;
                }
                set
                {
                    img = value;
                }
            }
            protected override void OnLocationChanged(EventArgs e)
            {
                //base.OnLocationChanged(e);
                Visible = false;
                Visible = true;
            }
            protected override CreateParams CreateParams
            {
                get
                {
                    //return base.CreateParams;
                    CreateParams cp = base.CreateParams;
                    cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT 
                    return cp;
                }
            }
            protected override void OnPaint(PaintEventArgs pe)
            {
                if (img != null)
                {
                    base.OnPaint(pe);
                    pe.Graphics.DrawImage(img, 0, 0);
                }
                else
                {
                }
            }
        }
    
    //注:如果是手动改变图片,最好在刷新一下界面(this.Refresh();),记着图片要是透明的才能实现透明
    

      

  • 相关阅读:
    gcvt(),ecvt(),fcvt()的区别
    SQLITE3 使用总结
    C++的类型转换浅析
    JAVA Class21
    JAVA Class20
    JAVA Class19
    JAVA Class18
    JAVA Class17
    JAVA Class16
    关于hover失效问题(!important)
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/3164318.html
Copyright © 2011-2022 走看看