I want to do textBox a Transparent Background c# .net Visual Studio is making a mistake if you define Properties
-
3Could you elaborate and show your code? – Emond Apr 05 '11 at 19:28
-
I just want to integrate graphics and put the image transparent textbox that hides the graphics – shlomi Apr 05 '11 at 19:33
-
Sorry this comment is not helping. What did you try? What mistake and Properties are you referring to? – Emond Apr 05 '11 at 19:40
-
2This is not possible. You'll have to move to WPF to get it. – Hans Passant Apr 05 '11 at 20:29
-
Check out my answer here: http://stackoverflow.com/a/19733917. Tell me if this helps... – Shahid M Zubair Feb 03 '14 at 16:49
3 Answers
Put this in the constructor:
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
The class need to enable the transparent style. (For some reason it isn't supported by default).
public class MyControl : System.Windows.Forms.UserControl
{
public MyControl ()
{
// Create visual controls
InitializeComponent();
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}
}
Or if it's not a custom control:
mycontrolObject.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
More about Control.SetStyle Method
Other Control Styles

- 48,127
- 24
- 147
- 185
-
2This will not work for a TextBox. .NET TextBox is just a wrapper for the old Win32 control so he will need to do some kind of sub-classing. – HABJAN Apr 05 '11 at 19:50
-
2Even when I sub-classed TextBox this didn't work. I can successfully set the BackColor property to Color.Transparent (it no longer throws an exception), but the textbox is not actually transparent - I cannot see the control behind it. – EM0 Jan 17 '13 at 05:28
I've found a workaround for this problem, which I have on my own.
Most of what I've read over here is true. And the approaches "à la" AlphaBlendTextBox
are way too complex or too time-consuming for some environments, already heavily charged.
Assume you have a given background color and a given picture or whatever you want to see through the RichTextBox
control. This is what I've done (summarized):
- on the main form, you place the picture, text, buttons or whatever as projected, with the proper background color and / or picture
- create a new form and position it wherever appropriate
- set this new form
TransparencyKey
toSystemColors.InactiveBorder
- take care of this form border properties (
FormBorderStyle
toFormBorderStyle.None
;ControlBox
,MinimizeBox
,MaximizeBox
andShowIcon
tofalse
,TopMost
totrue
,StartPosition
toFormStartPosition.Manual
,SizeGripStyle
toSizeGripStyle.Hide
), so there's no visible form structures - create a
RichTextBox
with the same size of the form and located on its upper, left corner - set this box
BackColor
toSystemColors.InactiveBorder
(remember the TransparencyKey?) and itsBorderStyle
to None as well - take care of textbox contents: color(s), font(s) and strings
- synchronize this form visibility with whatever you need to and... voilà! You can see your application background through whatever you write and edit on the text box!
I can't pretend this approach fits everybody, but it is way simpler than others I've seen and, as long as I can keep it that way, I do prefer the simpler solutions.
Of course, when you close the main form, you must take care of the child form, but this is pretty basic for you, isn't it?
Enjoy!

- 134
- 7
-
I had pondered something like this but steps 3+6 never crossed my mind. So it works for you? – TaW Apr 21 '14 at 16:56
This is not an easy task. .Net TextBox control is a wrapper around Win32 Edit control, so you will need to do sub-classing to achieve background transparency.
Take a look at this sample: AlphaBlendTextBox - A transparent/translucent textbox for .NET

- 9,212
- 3
- 35
- 59
-
4That code project is like a virus. It isn't a text box, it just looks like one. – Hans Passant Apr 05 '11 at 20:31
-
@HansPassant can you confirm that it is a virus? or are you just not impressed with the implementation? – Jeremy Thompson Aug 24 '13 at 02:20
-
1@Jeremy - it is code that duplicates itself because it looks attractive but gets its users in trouble all the time. – Hans Passant Aug 24 '13 at 08:24