Textbox padding

dab picture dab · Feb 4, 2011 · Viewed 56k times · Source

I've searched through the internet, I must be using the wrong keywords because I can't find anything. I want to create a textbox that has text starting from a little far from the left.

http://dab.biz/images/screenie/2011-02-04_1316.png

Just like that.

Answer

Nimrod picture Nimrod · Feb 4, 2011

As you have most likely discovered, Winforms Textboxes do not have a padding property. Since Panels do expose a Padding property, one technique would be to:

  1. Create a Panel
  2. Set its border to match a Textbox (e.g., Fixed3D)
  3. Set its background color to match a Textbox (e.g., White or Window)
  4. Set its padding to your satisfaction (e.g., 10,3,10,3)
  5. Add a Textbox inside the panel
  6. Set the Textbox's border to none
  7. Play with the Textbox's Dock and Anchor properties do get desired effect

This should get you started. You could also create a custom control that does the same thing as mentioned above.

In case you were talking about Textboxes in asp.net, just use CSS:
input[type="text"] {padding: 3px 10px}