Reputation: 17183
I have an application in which I have used radio button over an image so it seems very bad with white background in radio button.
So is there a way I can remove that white background ?
Upvotes: 0
Views: 2906
Reputation: 3182
Locate the constructor for your control class. The constructor appears in the control's code file. In C#, the constructor is the method with the same name as the control and with no return value.
Call the SetStyle method of your form in the constructor.
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
add the following line. This will set your control's BackColor to Transparent.
this.BackColor = Color.Transparent;
Note Windows Forms controls do not support true transparency. The background of a transparent Windows Forms control is painted by its parent.
Upvotes: 1
Reputation: 2152
Only setting the BackColor
to Color.Transparent
is not enough to get rid of the little border that is around the RadioButton
.
What you will need to also do is call the following code for each radio button to ensure that the background does actually go transparent
rbnTest.BackColor = Color.Transparent;
Point pos = this.PointToScreen(rbnTest.Location);
rbnTest.Parent = pibPicture;
rbnTest.Location = pibPicture.PointToClient(pos);
Source (Not a true duplicate, but similar, hence not flaggin as duplicate)
I would recommend refactoring that code into a reusable method so that you do not scatter the code all over your project.
Upvotes: 2
Reputation: 5131
You can use the RadioButton.BackgroundImage
or the RadioButton.BackColor
property. Choose the one that suits you best
Upvotes: -1