2015-12-17 56 views
0

我有一个窗体与背景图像和透明度键。 在这种形式中,我把儿童形式,必须是完全透明的,以显示父窗体的背景。如果我将另一个透明度键设置为子窗体 - 它根本不会获得透明度,并且如果我设置了父窗体的透明度键 - 子窗体切入父窗体的背景图像。父母形式的透明子窗体与透明度和背景

我需要使用窗体 - 不是用户控制,所以这是一个问题。我不想将dublicate背景图像设置为子窗体。

我的视觉工作。下面是来自设计师代码:

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

那是小孩在银行里面的情况,现在它有透明钥匙银牌。 如果我设置this.BackColor = System.Drawing.Color.DarkRed;给孩子 - 它会刺破父母的背景。

下面是我的意思的一些图像。

Child with other then parent transparency key

Child with same as parent transparency

+0

向我们展示一些代码,以便我们可以看到您尝试过的内容。 – StijnvanGaal

+0

增加了一些代码。 – Kodek

回答

0

我不知道为什么你的子窗体的背景刺入的主要形式。 有两件事你可以尝试。

  1. 尝试设置为您最有可能不会使用的不同颜色。像Color.Magenta一样。 (Altough据我所知,你可能已经试过这已经)

  2. 您应该能够设置背景色透明here

    Button1.BackColor = Color.Transparent;

+0

嗯,我在例子中用DarkRed试了一下。如果两者都具有相同的颜色 - 孩子穿透父母。如果孩子有其他颜色 - 它不透明。 问题是我需要将透明颜色设置为整个窗体,而不是单个元素,因为我在面板中显示窗体。如果我将控制颜色设置为透明 - 它将相对于它的父项透明 - 我的“子”形式。而孩子形式依然不会透明或者会刺破父母。 – Kodek

+0

你的主要需要透明度键吗?也许这就是它穿透它的原因 – StijnvanGaal

+0

是的,它需要透明度,导致主要原因是PNG-8格式的背景图像给屏幕上没有任何边界的简单打开的书的效果。你可以在屏幕截图中看到它 - 已经推出的解决方案,你可以注意到没有国界的书。 – Kodek