【发布时间】:2016-03-23 17:22:48
【问题描述】:
我有一个带有背景图像和透明度键的表单。 在该表单中,我放置了必须完全透明的子表单以显示父表单的背景。如果我为子窗体设置另一个透明度键 - 它根本不会获得透明度,并且如果我设置父窗体的透明度键 - 子窗体会切穿父窗体的背景图像。
我需要使用表单而不是用户控件,所以这是一个问题。而且我不想将重复的背景图像设置为子窗体。
我在视觉上工作。这是设计师的代码:
-
那是我的父母
// // 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); -
这就是我将孩子插入父母面板的方式:
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(); } -
这是我的孩子:
// // 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; 设置为 Child - 它会穿透父母的背景。
这是我的意思的一些图像。
【问题讨论】:
-
向我们展示一些代码,以便我们了解您的尝试。