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.
Just like that.
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.
Just like that.
OK, here is a proper solution. First of all set
Multiline
of your TextBox control totrue
.Needed using statements:
Code:
Now call like so:
Of course, best is to create your own TextBox control which can automatically set
Multiline
to true and stop unwanted lines breaks in the text etc..Well, you can TrimLeft, then concatenate with 5 spaces. Or, you can set up a custom UserControl with a borderless TextBox as the actual entry element, overlaying another TextBox that doesn't have a tabstop and will shift focus to the borderless one when it's focused.
Expanding upon a response above and a perceived drawback of being able to backspace through the padded value. The SelectionStart property of the textbox can be used to determine where to position cursor when the TextChanged event fires.
In this example, the textbox is padded at the beginning with 2 spaces so that the information displayed will align with other non-input controls where the padding property is used.
I know this is a bit old. But here is a solution. For the initial text, add a space at the beginning. Then, you can override the
OnKeyPress
event and add the following code so that you can't backspace.You can replace the 1 with number of spaces to pad.
This question has recommended answer already. Anyway I would like to put alternative answer. To add padding to the textbox in c#,you can use "padLeft" method. Hope this help to someone.
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:
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}