简体   繁体   English

我可以在WinForms的PictureBox上创建透明背景吗?

[英]Can I create a transparent background on a PictureBox in WinForms?

I want to make the background of a PictureBox control transparent. 我想使PictureBox控件的背景透明。 In the PictureBox (rectangular shape), I placed an icon (circular in shape). PictureBox (矩形)中,放置了一个图标(圆形)。 I want to make the icon transparent so that the other portion underneath the icon is visible. 我想使图标透明,以使图标下面的其他部分可见。

I have tried setting the PictureBox.BackColor property to "Transparent", but it doesn't work. 我尝试将PictureBox.BackColor属性设置为“透明”,但是它不起作用。 I also tried to set it during runtime with the Color.FromArgb method, but it doesn't work either. 我还尝试在运行时使用Color.FromArgb方法设置它,但是它也不起作用。

Is there any solution to this problem? 有什么解决办法吗?

Setting pictureBox.BackColor = Color.Transparent; 设置pictureBox.BackColor = Color.Transparent; definitely should work. 绝对应该工作。

Also verify if you are setting alpha channel of color when using Color.FromArgb(0, 0, 0, 0) ; 还请验证在使用Color.FromArgb(0, 0, 0, 0)时是否设置了颜色的Alpha通道; (this is a first parameter, zero means transparent color) (这是第一个参数,零表示透明颜色)

And, of course, make sure your icons have transparent background. 并且,当然,请确保您的图标具有透明背景。

If using WinForms then Setting the background color to transparent won't work as transparency handling is not a cascading system - you can only (in most cases) set transparency (or rather the opacity) of a control overall using the Opacity property, however this will alter the alpha channel of the entire control display giving your images a see-througness. 如果使用WinForms则将背景颜色设置为透明将不起作用,因为透明处理不是一个级联系统-您只能(在大多数情况下)使用Opacity属性设置整个控件的透明性(或更确切地说是不透明度),但是会改变整个控件显示的Alpha通道,使您的图像通透。

One solution might be to set the background color of the PictureBox to be that of the control beneath it (the color of the form, for example). 一种解决方案可能是将PictureBox的背景色设置为其下方控件的背景色(例如,表单的颜色)。 But this may not suffice in your situation. 但这可能不足以满足您的情况。

hi you must set the icon on the other portion underneath the icon by using this 嗨,您必须使用此图标将图标设置在图标下方的其他部分上

icon_pictureBox_name.Controls.Add(other_portion_picturBox_name); icon_pictureBox_name.Controls.Add(other_portion_picturBox_name);

and after that you can set the PictureBox.BackColor property to "Transparent" and it will work ;) 然后,您可以将PictureBox.BackColor属性设置为“透明”,它将起作用;)

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

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