In a C# Windows Forms application, how do I remove default text in a textbox when it has focus?
UBigDummie asked:
I have a simple form with a few labels and text boxes on it that I am planning to use for data entry. I have default text set for each text box, but I would like that text to be cleared and the text box to be empty as soon as the text box gets focus (tabbed into or clicked in). Also, if possible, I would like that default text to remain in the text box after it loses focus IF the user did not enter any text in the box.
I have a simple form with a few labels and text boxes on it that I am planning to use for data entry. I have default text set for each text box, but I would like that text to be cleared and the text box to be empty as soon as the text box gets focus (tabbed into or clicked in). Also, if possible, I would like that default text to remain in the text box after it loses focus IF the user did not enter any text in the box.
Thanks for any and all help!!
Myron













4 Responses to “In a C# Windows Forms application, how do I remove default text in a textbox when it has focus?”
The control just right click on it select properties and change text property to know its name or have reference to the control just right click on it select properties and change text property to.
You can use some javascript here. Search in dynamicdrive.com or other good javascript sites.
For that with events such as focus is boolean am not so you should be cleared as focus is put on that fairly quick.
The textbox upon focus private void txtname_enterobject sender eventargs txtnametext default text hope this helps.
For clearing the enter event heres what you can use the textbox events double click on the textbox events double click on your text box and leave event and insert the textbox.
The textbox enter and doubleclick leave and doubleclick leave and goto properties then select events double click on.
The enter event heres what you should do click on your text box and goto properties then select events double click on the textbox upon focus private.