I want to make the background of a PictureBox
control transparent. In the PictureBox
(rectangular shape), I placed an icon (circular in shape). I want to make the icon transparent so that the other portion underneath the icon is visible.
我想让PictureBox控件的背景透明。在PictureBox(矩形)中,我放置了一个图标(圆形)。我想让图标透明,以便图标下方的其他部分可见。
I have tried setting the PictureBox.BackColor
property to "Transparent", but it doesn't work. I also tried to set it during runtime with the Color.FromArgb
method, but it doesn't work either.
我已经尝试将PictureBox.BackColor属性设置为“透明”,但它不起作用。我还尝试在运行时使用Color.FromArgb方法设置它,但它也不起作用。
Is there any solution to this problem?
有没有解决这个问题的方法?
3 个解决方案
#1
4
Setting pictureBox.BackColor = Color.Transparent;
definitely should work.
设置pictureBox.BackColor = Color.Transparent;绝对应该工作。
Also verify if you are setting alpha channel of color when using Color.FromArgb(0, 0, 0, 0)
; (this is a first parameter, zero means transparent color)
同时验证在使用Color.FromArgb(0,0,0,0)时是否设置了颜色的alpha通道; (这是第一个参数,零表示透明色)
And, of course, make sure your icons have transparent background.
当然,请确保您的图标具有透明背景。
#2
2
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). But this may not suffice in your situation.
一种解决方案可能是将PictureBox的背景颜色设置为其下方控件的背景颜色(例如,表单的颜色)。但在你的情况下这可能还不够。
#3
0
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属性设置为“透明”,它将工作;)
#1
4
Setting pictureBox.BackColor = Color.Transparent;
definitely should work.
设置pictureBox.BackColor = Color.Transparent;绝对应该工作。
Also verify if you are setting alpha channel of color when using Color.FromArgb(0, 0, 0, 0)
; (this is a first parameter, zero means transparent color)
同时验证在使用Color.FromArgb(0,0,0,0)时是否设置了颜色的alpha通道; (这是第一个参数,零表示透明色)
And, of course, make sure your icons have transparent background.
当然,请确保您的图标具有透明背景。
#2
2
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). But this may not suffice in your situation.
一种解决方案可能是将PictureBox的背景颜色设置为其下方控件的背景颜色(例如,表单的颜色)。但在你的情况下这可能还不够。
#3
0
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属性设置为“透明”,它将工作;)