現在我面臨著透明度鍵的問題。我也設定了所需的表單(希望顯示為對話框)TransparencyKeyColor.White和 BackColor Color.White。該表單使用的文本 ForeColor 是ControlText。
當背景應用程式具有白色/控制背景顏色時的外觀(

當對話框顯示在應用程式頂部時,看起來像:

我可以看到 Form 顯示透明背景,當背景顏色為白色時看起來也不錯。但是當背景顏色是深色主題色(像黑色、灰色等)時,它看起來很可怕,并且有一些白色的輪廓。我該怎么做才能防止這種情況發生?
編輯:抱歉缺少資訊。表單中顯示的文本是Label物件。對于那些代碼組屬性喜歡TransparencyKey,BackColor等是在designer.cs。這里是designer和.cs的代碼。
ReaderInitializer.cs
public partial class ReaderInitializer : Form
{
Reader _reader;
/// <summary>
/// Occur when being notify to close this screen.
/// </summary>
private event EventHandler NotifyClose;
public ReaderInitializer()
{
InitializeComponent();
NotifyClose = OnClose;
try
{
lbl_Message.Text = "Please insert the card.";
pb_Icon.Image = new Bitmap($@"{ProgramInfo.RootPath}\img\init\load.png");
}
catch (Exception e)
{
SystemLog.Write(e);
}
}
public void SetReaderNotify(Reader reader)
{
reader.MapSuccess = ReaderInitSuccess;
_reader = reader;
}
private void ReaderInitSuccess(object sender, MapSuccessEventArgs e)
{
Action uiAction = () =>
{
lbl_Message.Text = e.Message;
pb_Icon.Image = e.DisplayImage;
if (_reader != null)
_reader.MapSuccess -= ReaderInitSuccess;
};
if (InvokeRequired)
{
Invoke((MethodInvoker)delegate { uiAction(); });
}
else
{
uiAction();
}
NotifyClose?.Invoke(this, new EventArgs());
}
private void OnClose(object sender, EventArgs e)
{
// Suspecting causing hang when closing dialog.
Task.Delay(3000).Wait();
Close();
}
}
ReaderInitializer.Designer.cs
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tlp_Icon = new System.Windows.Forms.TableLayoutPanel();
this.pn_Header = new System.Windows.Forms.Panel();
this.pn_Footer = new System.Windows.Forms.Panel();
this.pn_Message = new System.Windows.Forms.Panel();
this.pb_Icon = new System.Windows.Forms.PictureBox();
this.lbl_Message = new System.Windows.Forms.Label();
this.tlp_Icon.SuspendLayout();
this.pn_Message.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pb_Icon)).BeginInit();
this.SuspendLayout();
//
// tlp_Icon
//
this.tlp_Icon.ColumnCount = 3;
this.tlp_Icon.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F));
this.tlp_Icon.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 70F));
this.tlp_Icon.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F));
this.tlp_Icon.Controls.Add(this.pb_Icon, 1, 0);
this.tlp_Icon.Location = new System.Drawing.Point(0, 42);
this.tlp_Icon.Margin = new System.Windows.Forms.Padding(0);
this.tlp_Icon.Name = "tlp_Icon";
this.tlp_Icon.RowCount = 1;
this.tlp_Icon.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tlp_Icon.Size = new System.Drawing.Size(800, 258);
this.tlp_Icon.TabIndex = 0;
//
// pn_Header
//
this.pn_Header.Dock = System.Windows.Forms.DockStyle.Top;
this.pn_Header.Location = new System.Drawing.Point(0, 0);
this.pn_Header.Margin = new System.Windows.Forms.Padding(0);
this.pn_Header.Name = "pn_Header";
this.pn_Header.Size = new System.Drawing.Size(800, 42);
this.pn_Header.TabIndex = 1;
//
// pn_Footer
//
this.pn_Footer.Dock = System.Windows.Forms.DockStyle.Bottom;
this.pn_Footer.Location = new System.Drawing.Point(0, 400);
this.pn_Footer.Margin = new System.Windows.Forms.Padding(0);
this.pn_Footer.Name = "pn_Footer";
this.pn_Footer.Size = new System.Drawing.Size(800, 50);
this.pn_Footer.TabIndex = 2;
//
// pn_Message
//
this.pn_Message.Controls.Add(this.lbl_Message);
this.pn_Message.Dock = System.Windows.Forms.DockStyle.Bottom;
this.pn_Message.Location = new System.Drawing.Point(0, 300);
this.pn_Message.Margin = new System.Windows.Forms.Padding(0);
this.pn_Message.Name = "pn_Message";
this.pn_Message.Size = new System.Drawing.Size(800, 100);
this.pn_Message.TabIndex = 3;
//
// pb_Icon
//
this.pb_Icon.Dock = System.Windows.Forms.DockStyle.Fill;
this.pb_Icon.Location = new System.Drawing.Point(120, 0);
this.pb_Icon.Margin = new System.Windows.Forms.Padding(0);
this.pb_Icon.Name = "pb_Icon";
this.pb_Icon.Size = new System.Drawing.Size(560, 258);
this.pb_Icon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pb_Icon.TabIndex = 0;
this.pb_Icon.TabStop = false;
//
// lbl_Message
//
this.lbl_Message.Dock = System.Windows.Forms.DockStyle.Fill;
this.lbl_Message.Font = new System.Drawing.Font("Roboto", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl_Message.Location = new System.Drawing.Point(0, 0);
this.lbl_Message.Margin = new System.Windows.Forms.Padding(0);
this.lbl_Message.Name = "lbl_Message";
this.lbl_Message.Size = new System.Drawing.Size(800, 100);
this.lbl_Message.TabIndex = 0;
this.lbl_Message.Text = "...";
this.lbl_Message.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ReaderInitializer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.pn_Message);
this.Controls.Add(this.pn_Footer);
this.Controls.Add(this.pn_Header);
this.Controls.Add(this.tlp_Icon);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "ReaderInitializer";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Guest Service Station";
this.TransparencyKey = System.Drawing.Color.White;
this.tlp_Icon.ResumeLayout(false);
this.pn_Message.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pb_Icon)).EndInit();
this.ResumeLayout(false);
}
uj5u.com熱心網友回復:
你有這個問題:

我已將 Form 的BackColor和更改TransparencyKey為紫紅色,并將更改Label.ForeColor為灰色。請注意如何TransparencyKey勾勒文本。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/377594.html
