1

I've made a custom textbox in Photoshop, and I want to apply it. I know, that you can't change the background in Visual Studio, or make it transparent. I've seen a few methods on how to do it, but they weren't very clear.

So I want to ask you - what is the esiest way to change the background of a textbox or make it transparent?

pravprab
  • 2,301
  • 3
  • 26
  • 43
  • Is it winform or wpf? – Sajeetharan Apr 21 '14 at 08:43
  • In Winforms no controls support tranparency. (Except forms.) You may succeed in creating a custom textbox, but it will be tricky! See these posts: [How to draw on top of a TextBox](http://stackoverflow.com/questions/4378148/how-to-draw-on-top-of-a-textbox) and [Textbox custom onPaint](http://stackoverflow.com/questions/17414693/textbox-custom-onpaint) If I were you, I probably would give up using a TextBox and use a panel where I would capture keys to collect the Text and draw it on top of my background image. The TextBox doesn't do that much, does it? – TaW Apr 21 '14 at 10:20
  • That sounds like a solution. Could you give me some more information about that method? (panel) – user3533051 Apr 21 '14 at 11:11
  • maybe it would be easier if you'd explain a little more what your situation is, like how big is the image? will it be stretched? How much text will be in the textbox? how will it be edited..? The basic idea is to capture all keys and either add them to the text or do the editing the textbox would do with them. If implemented completely it will be some work, but maybe a partial implementation would be enough.. – TaW Apr 21 '14 at 12:56
  • Sure, I'll explain. I've made this design in Photoshop: http://prntscr.com/3c1ug8 All the items are the exact same size as it should be: the button, the form, the textbox. Nothing will be stretched. I've already successfully changed the background and the button, nowit's time for the textboxes. – user3533051 Apr 21 '14 at 13:30
  • @TaW `use a panel where I would capture keys to collect the Text and draw it on top of my background image` - sorry, your advice is really odd. Instead of recommending the OP to reinvent the wheel, tell them to use proper technology (WPF) which allows customization of the UI without resorting to any horrible hacks like that. – Federico Berasategui Apr 21 '14 at 23:02
  • 1
    Definitly true - I have been learning a lot about WPF in the last couple of days and if going that way is an option it would make stuff like this really easy. But changing to WPF is a big decision and is is not mine to make nor yours. Investing such an enourmous amount of work/money for one small control is quite a decision; and I really can't say that I like what I have seen in WPF so far.. (xaml is (to the human eye) unstructured and unreadable; the desigenr a piece of crap, the debugging problems ridiculous and 99% of the new options of no interest at all.. ) – TaW Apr 22 '14 at 01:55
  • @TaW sorry, didn't read your comment before. `I really can't say that I like what I have seen in WPF so far` - You're approaching WPF with a winforms mentality. You need to understand [**The WPF Mentality**](http://stackoverflow.com/a/15684569/643085) first. Once you realize that everything is easily achieved with DataBinding and a proper ViewModel, you'll realize how winforms is a useless dinosaur and will never ever want to ever look back at it again. BTW, no one cares about the designer, I just disabled it completely. – Federico Berasategui Apr 22 '14 at 20:19

2 Answers2

0

Not sure about transparency, but changing the background of a text box is simple, check this link:

XAML: http://www.c-sharpcorner.com/UploadFile/mahesh/XAMLTextBox04092007062405AM/XAMLTextBox.aspx

Also, if working on WinForms; you have the BackColor property that works in the same way: http://msdn.microsoft.com/en-us/library/s2kh9x59(v=vs.110).aspx

EDIT:

You can do it by using a richtextbox instead... kind of.

http://www.codeproject.com/Articles/4544/Insert-Plain-Text-and-Images-into-RichTextBox-at-R http://www.codeproject.com/Articles/12135/Inserting-images-into-a-RichTextBox-control-the-OL

Nahuel Ianni
  • 3,177
  • 4
  • 23
  • 30
0

You need to Add a new user control , say CustomTextBox and Put this inside the constructor, which will make it transparent

SetStyle(ControlStyles.SupportsTransparentBackColor, true);

C# transparency on textbox

Community
  • 1
  • 1
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396