Add static text to TextBox

I am developing a custom TextBox to display and edit currency values. I would like to have a currency symbol visible within the TextBox on the left. Overriding OnPaint of TextBox is the horror after Googling and doing some tests. Does anyone have any other ideas? Maybe add a character as a background image in a TextBox (if it's pretty simple)?

+4
source share
5 answers

why don’t you put a shortcut in front of the text box and display the currency value?

+1
source

why not just:

  private void textBox1_TextChanged(object sender, EventArgs e) { if (!textBox1.Text.StartsWith("Β£")) { textBox1.Text = string.Concat("Β£", textBox1.Text); textBox1.Select(textBox1.Text.Length, 0); } } 
+1
source

You can do a few things:

  • Add "$" to the get property of your text box
  • Add tag with static $
  • Create a custom control using the $ sign as a shortcut and reuse it in your text box
0
source

Another option is to use a watermark in your text box - see here for an example of how to do this.

0
source

You can use MaskedTextBox instead of TextBox. http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.mask.aspx

For your Mask property, use the "$" symbol for the currency symbol.

0
source

All Articles