c# 自定义控件透明,自定义透明窗体
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(38, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(107, 12);
this.label1.TabIndex = 0;
this.label1.Text = "这个窗体是透明的!";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Red; //注意backColor的颜色要与TransparencyKey的颜色统一。
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.label1);
this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(200)))), ((int)(((byte)(105)))));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form1";
this.Text = "Form1";
this.TransparencyKey = System.Drawing.Color.Red; //注意backColor的颜色要与TransparencyKey的颜色统一。
this.Load += new System.EventHandler(this.Form1_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.formMain_Paint);
this.ResumeLayout(false);
this.PerformLayout();
}
测试效果如下: