GUI 白色变透明

GUI White becomes Transparent

我用 C# 编写了一个 GUI 窗体。当我执行程序时,白色变成透明的。

应该是这样的:

但是我运行的时候是这样的:

你可以看到像后面的图片一样,白色变成了黑色。

using System;
using System.Drawing;

namespace Taki_Client
{
    partial class SignIn
    {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.btnMenu = new System.Windows.Forms.Button();
        this.picSignIn = new System.Windows.Forms.PictureBox();
        this.btnSubmit = new System.Windows.Forms.Button();
        this.tbUsername = new System.Windows.Forms.TextBox();
        this.tbPassword = new System.Windows.Forms.TextBox();
        ((System.ComponentModel.ISupportInitialize)(this.picSignIn)).BeginInit();
        this.SuspendLayout();
        // 
        // btnMenu
        // 
        this.btnMenu.BackgroundImage = global::Taki_Client.Properties.Resources.Menu_Button;
        this.btnMenu.Location = new System.Drawing.Point(314, 476);
        this.btnMenu.Name = "btnMenu";
        this.btnMenu.Size = new System.Drawing.Size(157, 57);
        this.btnMenu.TabIndex = 4;
        this.btnMenu.UseVisualStyleBackColor = true;
        this.btnMenu.MouseClick += new System.Windows.Forms.MouseEventHandler(this.btnExit_MouseClick);
        // 
        // picSignIn
        // 
        this.picSignIn.BackColor = System.Drawing.Color.Transparent;
        this.picSignIn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
        this.picSignIn.ErrorImage = null;
        this.picSignIn.Image = global::Taki_Client.Properties.Resources.SignIn;
        this.picSignIn.ImageLocation = "";
        this.picSignIn.Location = new System.Drawing.Point(272, 12);
        this.picSignIn.Name = "picSignIn";
        this.picSignIn.Size = new System.Drawing.Size(288, 161);
        this.picSignIn.TabIndex = 0;
        this.picSignIn.TabStop = false;
        this.picSignIn.Click += new System.EventHandler(this.pictureBox1_Click);
        // 
        // btnSubmit
        // 
        this.btnSubmit.BackgroundImage = global::Taki_Client.Properties.Resources.Submit_Button;
        this.btnSubmit.Location = new System.Drawing.Point(314, 347);
        this.btnSubmit.Name = "btnSubmit";
        this.btnSubmit.Size = new System.Drawing.Size(157, 57);
        this.btnSubmit.TabIndex = 5;
        this.btnSubmit.UseVisualStyleBackColor = true;
        this.btnSubmit.MouseClick += new System.Windows.Forms.MouseEventHandler(this.btnSubmit_MouseClick);
        // 
        // tbUsername
        // 
        this.tbUsername.BackColor = System.Drawing.SystemColors.HotTrack;
        this.tbUsername.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(177)));
        this.tbUsername.ForeColor = System.Drawing.SystemColors.Menu;
        this.tbUsername.Location = new System.Drawing.Point(314, 223);
        this.tbUsername.Multiline = true;
        this.tbUsername.Name = "tbUsername";
        this.tbUsername.Size = new System.Drawing.Size(201, 44);
        this.tbUsername.TabIndex = 6;
        this.tbUsername.Text = "Username";
        // 
        // tbPassword
        // 
        this.tbPassword.BackColor = System.Drawing.SystemColors.HotTrack;
        this.tbPassword.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(177)));
        this.tbPassword.ForeColor = System.Drawing.SystemColors.Menu;
        this.tbPassword.Location = new System.Drawing.Point(314, 284);
        this.tbPassword.Multiline = true;
        this.tbPassword.Name = "tbPassword";
        this.tbPassword.Size = new System.Drawing.Size(201, 44);
        this.tbPassword.TabIndex = 7;
        this.tbPassword.Text = "Password";
        // 
        // SignIn
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.SystemColors.ActiveCaption;
        this.BackgroundImage = global::Taki_Client.Properties.Resources.Taki_main_screen;
        this.ClientSize = new System.Drawing.Size(804, 611);
        this.Controls.Add(this.tbPassword);
        this.Controls.Add(this.tbUsername);
        this.Controls.Add(this.btnSubmit);
        this.Controls.Add(this.btnMenu);
        this.Controls.Add(this.picSignIn);
        this.Name = "SignIn";
        this.Text = "Taki Client";
        this.TransparencyKey = System.Drawing.Color.Transparent;
        this.Load += new System.EventHandler(this.Form1_Load);
        ((System.ComponentModel.ISupportInitialize)(this.picSignIn)).EndInit();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.PictureBox picSignIn;
    private System.Windows.Forms.Button btnMenu;
    private System.Windows.Forms.Button btnSubmit;
    private System.Windows.Forms.TextBox tbUsername;
    private System.Windows.Forms.TextBox tbPassword;
  }
}

通过设置表单的TransparencyKey,启用透明度。透明度的默认颜色为白色。

InitializeComponent () 函数中删除这一行

this.TransparencyKey = System.Drawing.Color.Transparent;

并且您表单上的白色将不再透明。