首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

[C#关于绘制透明控件的]

2013-08-04 
[C#关于绘制透明控件的求助]设计视图代码:public MyTransparentControl(){InitializeComponent()SetStyle

[C#关于绘制透明控件的求助]

设计视图

代码:

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



                return cp;
            }
        }



运行时:
[C#关于绘制透明控件的]
后面就是桌面……

为啥我不能实现这个效果:
[C#关于绘制透明控件的]
虚心求大神解答。 没人知道?
  同3楼 看法
[解决办法]
class TransparentControl:Control
{
   protected override CreateParams CreateParams
        {
            get
            {
                CreateParams para = base.CreateParams;
                para.ExStyle 
[解决办法]
= 0x00000020; //WS_EX_TRANSPARENT 透明支持
                return para;
            }
        }
        protected override void OnPaintBackground(PaintEventArgs e) //不画背景
        {
            //base.OnPaintBackground(e);
        }
        protected override OnPaint(PaintEventArgs e)


        {
             //绘制图形
        }
}

热点排行