简体   繁体   English

父级形式的透明子窗体具有透明度和背景

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

I have a form with background image and transparency key. 我有一个带有背景图像和透明度键的表格。 In that form I put child form which must be fully transparent to show bakground of the parent form. 在该表单中,我放置了子表单,该子表单必须完全透明才能显示父表单的背景。 If I set another transparency key to child form - it do not get transparency at all, and if i set transparency key of parent form - child cut through parent form's background image. 如果我为子窗体设置了另一个透明度键-它根本不会获得透明度,并且如果我设置了父窗体的透明度键-子将切穿父窗体的背景图像。

I need to use form - not user control so thats an issue. 我需要使用表格-而不是用户控制,所以这是一个问题。 And i dont want to set dublicate background image to child form. 而且我不想将双重背景图像设置为子窗体。

Im working visually. 我在视觉上工作。 Here's code from designer: 这是设计师的代码:

  1. That is my parent 那是我的父母

      // // 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. That is how I insert child into parent's panel: 这就是我将孩子插入家长面板的方式:

      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. Here is my Child: 这是我的孩子:

      // // 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); 

Thats the situation when child is Silver inside parent now matter that it has transparency key Silver. 那就是当孩子在父级中是Silver时的情况,因为它具有透明键Silver。 If i set this.BackColor = System.Drawing.Color.DarkRed; 如果我设置this.BackColor = System.Drawing.Color.DarkRed; to Child - it will pierce parent's background. 给孩子-它会刺穿父母的背景。

Here's some images of what i mean. 这是我的意思的一些图片。

Child with other then parent transparency key 带有其他父母透明键的孩子

Child with same as parent transparency 与父母透明度相同的孩子

I am not sure why your child form's background is piercing the main form. 我不确定您的孩子表格的背景为什么会刺穿主要表格。 There are two things you might try. 您可以尝试两种方法。

  1. try setting both to a different color which your are most likely not going to use. 尝试将两者都设置为您最有可能不会使用的其他颜色。 Like Color.Magenta . 就像Color.Magenta一样。 (Altough I understand that you might have tried this already) (尽管我知道您可能已经尝试过了)

  2. You should be able to set the Back color to transparent here 您应该可以在此处将“后退”颜色设置为透明

    Button1.BackColor = Color.Transparent; Button1.BackColor = Color.Transparent;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM