I'm using windows forms in C# and I need to make a textbox's background color transparent. I have a trackbar that goes from 0 to 255 that is supposed to control it, but I'm having some trouble. I created a question earlier today asking the exact same thing, but no success.
Here is the code I currently have:
private void trackAlpha_ValueChanged(object sender, EventArgs e)
{
newColor = Color.FromArgb(trackAlpha.Value, colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B);
colorDialog.Color = newColor; // The Windows dialog used to pick the colors
colorPreview.BackColor = newColor; // Textbox that I'm setting the background color
}
The problem is that absolutely nothing happens. Any ideas on why this is not working?
On the previous question, this nice guy said something about SetStyle(ControlStyles.SupportsTransparentBackColor, true);
, but I have no idea on where I should put this.
input[type=text] { background: transparent; border: none; } background-color:rgba(0,0,0,0);
TextBox1.BackColor = Me.BackColor ..which makes Textbox seem transparent if you're not using a background image.
Its simple try this. Click the button that you want to make transparent. Select FlatStyle from Properties and set it to popup Now change the BackColor property to Transparent . This will make the button transparent.
You need to try out something like this.
Add a new user control , say CustomTextBox and change
public partial class CustomTextBox : UserControl
to
public partial class CustomTextBox : TextBox
You will then get the following error saying that the 'AutoScaleMode' is not defined. Delete the following line in the Designer.cs class.
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
Make changes to the constructor of your newly added control as follows.
public partial class CustomTextBox : TextBox
{
public CustomTextBox()
{
InitializeComponent();
SetStyle(ControlStyles.SupportsTransparentBackColor |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.UserPaint, true);
BackColor = Color.Transparent;
}
}
Build, close the custom control designer if open and you will be able to use this control on any other control or form.
Drop it from the toolbox as shown below
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With