private void UserControl1_Load(object sender, EventArgs e)
        {
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.Opaque, false);
            this.BackColor = Color.Transparent;
        }
我这么设置了都不能透明

解决方案 »

  1.   

    public partial class UserControl1 : Form
        {
            public UserControl1()
            {
                InitializeComponent();
            }        private void UserControl1_Load(object sender, EventArgs e)
            {        }
        }
    将自定义控件继承Form的基类就可以有Opacity属性  就可以让控件透明
      

  2.   

    那样此控件就不是控件了 而是form了
      

  3.   

     SetStyle(
                   ControlStyles.UserPaint |
                   ControlStyles.AllPaintingInWmPaint |
                   ControlStyles.OptimizedDoubleBuffer |
                   ControlStyles.SupportsTransparentBackColor |
                   ControlStyles.Selectable |
                   ControlStyles.ResizeRedraw, true);
      

  4.   

    IUControl.cs控件代码: 
    public partial class IUControl: UserControl
        {
    public IUControl()
            {
                InitializeComponent();
                SetStyle(
                 ControlStyles.UserPaint |
                 ControlStyles.AllPaintingInWmPaint |
                 ControlStyles.OptimizedDoubleBuffer |
                 ControlStyles.SupportsTransparentBackColor |
                 ControlStyles.Selectable |
                 ControlStyles.ResizeRedraw, true);
            }
    }
    应用控件的页面代码            this.iuControl= new IUControl();
                this.Controls.Add(this.iuControl);
                this.iuControl.AutoSize = true;
                this.iuControl.Location = new System.Drawing.Point(65, 193);
                this.iuControl.Name = "iuCompass";
                this.iuControl.Size = new System.Drawing.Size(250,250);            
                this.iuControl.Text = "我的控件";            iuControl.BackColor = System.Drawing.Color.Transparent;
    但运行iuControl背景还是灰色的!
      

  5.   


    this.BackColor = Color.Transparent; //这条语句加在控件代码中
    this.AllowTransparency = true;         //这句代码加到form的代码里
      

  6.   

    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim cParms As CreateParams = MyBase.CreateParams
            cParms.ExStyle = cParms.ExStyle Or &H80000
            ' WS_EX_LAYERED 
            Return cParms
        End Get
    End Property