Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有透明度和背景的父窗体中的透明子窗体_C#_Winforms - Fatal编程技术网

C# 具有透明度和背景的父窗体中的透明子窗体

C# 具有透明度和背景的父窗体中的透明子窗体,c#,winforms,C#,Winforms,我有一个带有背景图像和透明键的窗体。 在那个表单中,我放置了子表单,它必须是完全透明的,以显示父表单的背景。若我将另一个透明度键设置为子窗体-它根本不会获得透明度,若我将父窗体的透明度键设置为-子窗体剪切父窗体的背景图像 我需要使用表单,而不是用户控件,所以这是一个问题。我不想把复杂的背景图像设置为子窗体 我在视觉上工作。以下是designer的代码: 那是我的父母 // // Main // this.AutoScaleDimensions = new Sy

我有一个带有背景图像和透明键的窗体。 在那个表单中,我放置了子表单,它必须是完全透明的,以显示父表单的背景。若我将另一个透明度键设置为子窗体-它根本不会获得透明度,若我将父窗体的透明度键设置为-子窗体剪切父窗体的背景图像

我需要使用表单,而不是用户控件,所以这是一个问题。我不想把复杂的背景图像设置为子窗体

我在视觉上工作。以下是designer的代码:

  • 那是我的父母

        // 
        // 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);
    
  • 这种情况下,当孩子是银在父母现在的问题,它有透明键银。 如果我设置
    this.BackColor=System.Drawing.Color.DarkRed到子级-它将穿透父级的背景

    这里有一些我的意思的图片


    我不知道为什么您的子窗体的背景会穿透主窗体。 有两件事你可以试试

  • 尝试将这两种颜色都设置为您最可能不使用的不同颜色。像
    颜色.洋红色
    。(虽然我知道你可能已经试过了)

  • 您应该能够将背景颜色设置为透明

    Button1.BackColor=颜色。透明


  • 向我们展示一些代码,这样我们就可以看到您尝试了什么。好吧,我在示例中使用了DarkRed。如果两者具有相同的颜色-子项穿透父项。如果孩子有其他颜色-它不会得到透明度。问题是我需要将透明颜色设置为整个窗体,而不是单个元素,因为我在面板中显示窗体。如果我将控件颜色设置为透明-相对于它的父-我的“子”窗体,它将是透明的。而且子窗体仍然不会是透明的,或者会刺穿父窗体。您的主窗体是否需要透明键?也许这就是它刺穿它的原因是的,它需要透明度,因为主要原因是PNG-8格式的背景图像在屏幕上提供了无边框的简单打开书的效果。你们可以在屏幕截图上看到它-有一个发布的解决方案,你们可以注意到无边框书。我试着从主窗体中删除透明度。同样的效果。所以这不是问题。子级或根本不透明,或者即使父级没有透明,也会感知父级。此外,还可以将主色和父级背景色的透明键设置为深色,然后将主色和子级透明键设置为另一种颜色,如蓝色。这有区别吗?