How can I make the text disappear from a textbox when I click on it? (On a windows form using Visual studio 2019 C++)
Asked
Active
Viewed 204 times
-2
-
Do you want the text to return if the user navigates away without typing anything? – user4581301 Jun 14 '21 at 18:03
-
Sounds like you are looking for "Cue Banner" text via the [`EM_SETCUEBANNER`](https://learn.microsoft.com/en-us/windows/win32/Controls/em-setcuebanner) window message. See [Watermark TextBox in WinForms](https://stackoverflow.com/questions/4902565/). – Remy Lebeau Jun 14 '21 at 19:23
-
@user4581301 No, I just need for the text to be cleared when the user clicks the textbox – Daelin Parmanand Jun 14 '21 at 20:45
-
Have you tried anything yet? – D J Jun 27 '21 at 09:50
1 Answers
-1
I suggest you could try to use Control.GotFocus Event. When the textbox gains focus, we could call TextBoxBase.Clear Method
Here is my code:
private: System::Void textBox1_OnGotFocus(System::Object^ sender, System::EventArgs^ e)
{
this->textBox1->Clear();
}

Jeaninez - MSFT
- 3,210
- 1
- 5
- 20