简体   繁体   English

无法将任何控件设置为在C#Winforms中透明

[英]Cannot set any controls to be transparent in C# Winforms

EDIT: I tested this with other controls, and they all seem to be unable to have transparency. 编辑:我用其他控件对此进行了测试,它们似乎都无法具有透明度。 I am using .net framework 4.5.2 When I set the .BackColor property of any control to Color.Transparent, they all show up as the same color as the background but I cannot see any controls under them. 我正在使用.net framework 4.5.2,当我将任何控件的.BackColor属性设置为Color.Transparent时,它们都显示为与背景相同的颜色,但是在它们下面看不到任何控件。 For example, I cannot make PictureBox transparent. 例如,我不能使PictureBox透明。

I've been trying everything to make a chart transparent (so I can see controls under it) 我一直在尝试使图表透明化(以便可以看到其下的控件)

This is for System.Windows.Forms.DataVisualization.Charting . 这是针对System.Windows.Forms.DataVisualization.Charting

I tried setting both the background and the foreground and the chart areas background and secondary background to transparent, but the chart is still the same color as the windows form (grayish-white). 我尝试将背景和前景以及图表区域的背景和辅助背景设置为透明,但是图表的颜色仍然与Windows窗体相同(灰白色)。

From what I read online, it's sufficient to set the background of the chart and chartArea0 (which is my only chart area) 根据我在网上阅读的内容,只需设置图表的背景和chartArea0(这是我唯一的图表区域)

As such: 因此:

Chart chart = new Chart();
chart.BackColor = Color.Transparent;
chart.ChartAreas.Add(new ChartArea("ChartArea1"));
chart.ChartAreas[0].BackColor = Color.Transparent;

Please let me know what I can do to make it transparent. 请让我知道如何使它透明。

It seems that WinForms only allow "fake transparency", By this definition, they are drawing the Parent object on the background of the child object. 似乎WinForms仅允许“伪透明”,根据此定义,它们在子对象的背景上绘制Parent对象。

Therefore, where I wanted to draw one chart on top of another, I needed to do the following: 因此,我想在一个图表之上绘制一个图表,需要执行以下操作:

chart1.Parent = chart2;
chart2.Parent = chart3;

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

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