日期:2014-05-17  浏览次数:20731 次

[C#关于绘制透明控件的求助]
本帖最后由 LYF610400210 于 2013-07-25 08:19:34 编辑

设计视图

代码:
public MyTransparentControl()
        {
            InitializeComponent();
           
            SetStyle(ControlStyles.SupportsTransparentBackColor

              | ControlStyles.UserPaint

              | ControlStyles.AllPaintingInWmPaint

              | ControlStyles.Opaque, true);

 
            base.CreateControl();
            
            this.BringToFront();
        }

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            for (int i = 0; i < this.Width; i += 100)//画线
            {
                e.Graphics.DrawLine(new Pen(Color.Gray), new Point(i + 50, 0), new Point(i, this.Height - 1));
            }
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                
                cp.Style |= 0x00000020;
                //WS_EX_TRANSPARENT