Can I create a transparent background on a PictureBox in WinForms?

时间秒杀一切 提交于 2019-12-07 02:50:43

问题


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.

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.

Is there any solution to this problem?


回答1:


Setting 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); (this is a first parameter, zero means transparent color)

And, of course, make sure your icons have transparent background.




回答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.

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.




回答3:


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

and after that you can set the PictureBox.BackColor property to "Transparent" and it will work ;)



来源:https://stackoverflow.com/questions/4983753/can-i-create-a-transparent-background-on-a-picturebox-in-winforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!