0

I am new to C#. I have a very simple Windows Forms Application that has a text Box, Label and a button. I got the user to enter their name in the text box and press the button and their name displays on the label. Now I want to make the application more user friendly, so before the user enters their name in the text box, I want the text "Enter your name: " to appear in the text box but once the user click inside the text box (to enter their name), I want the "instruction" to disappear from the text box. Are there any built in functions that does that in C#?

slugster
  • 49,403
  • 14
  • 95
  • 145
user2301717
  • 1,049
  • 1
  • 10
  • 13
  • there will be an event such as onclicked or similar, use that to delete your instruction text – morishuz May 01 '13 at 10:08
  • Just the relevant links for convinience: [**SO: Watermark System.Windows.Forms.TextBox using C#**](http://stackoverflow.com/questions/578193/watermark-system-windows-forms-textbox-using-c-sharp) and [**Bite my bytes: Watermarked TextBox in Windows Forms on .NET**](http://vidmar.net/weblog/archive/2008/11/05/watermarked-textbox-in-windows-forms-on-.net.aspx) – Nope May 01 '13 at 10:15

4 Answers4

1

What you are looking for, I think, is a watermark functionality you often see on web sites nowadays. See this SO question for multiple ways to do it:

Watermark in System.Windows.Forms.TextBox

However this is not beginner material by far. There is no built-in functionality for this behaviour in C#, so there is no 'easy' way to do it.

Community
  • 1
  • 1
pyrocumulus
  • 9,072
  • 2
  • 43
  • 53
1

On the UI Designer mode, goto the textbox properties and type in the "enter your name" into the 'Text' Property, this will then show 'enter your name' in your textbox

Over more, if you think this is not suited, you may want to look into tooltips, these are easy to create and use and can be displayed when the end user hovers over the textbox

Philip Gullick
  • 995
  • 7
  • 22
  • This is not a watermark way, but as your a beginner this is what you want to use, just to help make it easier for you, and also help the end user. – Philip Gullick May 01 '13 at 10:11
0

What you're describing is a watermarked text box. I don't believe Winforms has a built-in one, but there are free solutions available. Maybe start here.

Community
  • 1
  • 1
Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
0

You'll be handling the click and focus event which is not a good way to go. In fact, just for something so simple, you'll end up with very complex code. And later on, if you wish to implement validations, your "instruction" text will become rather a pain.

DoomerDGR8
  • 4,840
  • 6
  • 43
  • 91