簡體   English   中英

父級形式的透明子窗體具有透明度和背景

[英]Transparent child form in parent form with transparency and background

我有一個帶有背景圖像和透明度鍵的表格。 在該表單中,我放置了子表單,該子表單必須完全透明才能顯示父表單的背景。 如果我為子窗體設置了另一個透明度鍵-它根本不會獲得透明度,並且如果我設置了父窗體的透明度鍵-子將切穿父窗體的背景圖像。

我需要使用表格-而不是用戶控制,所以這是一個問題。 而且我不想將雙重背景圖像設置為子窗體。

我在視覺上工作。 這是設計師的代碼:

  1. 那是我的父母

      // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.DarkRed; this.BackgroundImage = global::NWN_Tsuki.Properties.Resources.Book; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.ClientSize = new System.Drawing.Size(800, 665); this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.CloseBtn); this.DoubleBuffered = true; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.KeyPreview = true; this.MaximumSize = new System.Drawing.Size(800, 665); this.MinimumSize = new System.Drawing.Size(800, 665); this.Name = "Main"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Header"; this.TransparencyKey = System.Drawing.Color.DarkRed; this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Main_KeyDown); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Main_MouseDown); this.tableLayoutPanel1.ResumeLayout(false); this.ResumeLayout(false); 
  2. 這就是我將孩子插入家長面板的方式:

      private void LeftPanel_Paint(object sender, PaintEventArgs e) { ToC toc = new ToC(); toc.TopLevel = false; toc.AutoScroll = true; this.LeftContent.Controls.Add(toc); toc.FormBorderStyle = FormBorderStyle.None; toc.Dock = DockStyle.Fill; toc.Show(); } 
  3. 這是我的孩子:

      // // ToC // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Silver; this.ClientSize = new System.Drawing.Size(428, 396); this.Controls.Add(this.Ch7Btn); this.Controls.Add(this.Ch6Btn); this.Controls.Add(this.Ch5Btn); this.Controls.Add(this.Ch4Btn); this.Controls.Add(this.Ch3Btn); this.Controls.Add(this.Ch2Btn); this.Controls.Add(this.Ch1Btn); this.Controls.Add(this.label1); this.Name = "ToC"; this.Text = "ToC"; this.TransparencyKey = System.Drawing.Color.Silver; this.ResumeLayout(false); 

那就是當孩子在父級中是Silver時的情況,因為它具有透明鍵Silver。 如果我設置this.BackColor = System.Drawing.Color.DarkRed; 給孩子-它會刺穿父母的背景。

這是我的意思的一些圖片。

帶有其他父母透明鍵的孩子

與父母透明度相同的孩子

我不確定您的孩子表格的背景為什么會刺穿主要表格。 您可以嘗試兩種方法。

  1. 嘗試將兩者都設置為您最有可能不會使用的其他顏色。 就像Color.Magenta一樣。 (盡管我知道您可能已經嘗試過了)

  2. 您應該可以在此處將“后退”顏色設置為透明

    Button1.BackColor = Color.Transparent;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM