Matt Winer
Matt Winer

Reputation: 535

How to put an "X" (to clear a text box) inside the text box?

In my Windows application I would like to put an X at the right edge of a text box to clear it. Similar to what Google is using right now. Check out Google and do a search for anything. You'll see the X in the text box as soon as you've started typing something.

I know I can get away with just putting a button next to the text box. But I would like to do something a bit nicer.

Upvotes: 3

Views: 6507

Answers (3)

Nour Enbabi
Nour Enbabi

Reputation: 30

um sorry dude but in my opinion u can only do this by adding a button ( even inside the textbox) and set it as when it is clicked it clears the textbox

textbox.Clear(); 

Good Luck to You , Wish u the best

Upvotes: 0

CodingBarfield
CodingBarfield

Reputation: 3398

You could use custom painting to paint a little red icon on the rights side of you're control. Add some mouse click code to detect mouse clicks inside the little red icon to activate 'any' custom code.

Upvotes: 0

talha2k
talha2k

Reputation: 25483

Who says that google put an X in right end of text box....??

Thats not inside the google search text box. its outside of that textbox. and thats the onlyway you can do it. google use a table in which one td contains textbox while other contains 'X'. They've put some css which makes you feel like the X is inside textbox. Whixh is really not.

here is the html of google's search textbox:

<table cellspacing="0" cellpadding="0" style="width: 100%;"><tbody><tr><td class="gsib_a"><div style="position: relative; width: 100%; height: 25px;"><input type="text" maxlength="2048" name="q" id="lst-ib" class="gsfi" autocomplete="off" size="41" title="Search" value="mysql_num_rows" style="border: medium none; padding: 0pt 0pt 0pt 2px; margin: 0pt; width: 100%; outline: medium none; top: 1px; background: url(&quot;data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D&quot;) repeat scroll 0% 0% transparent; overflow: hidden; position: absolute; z-index: 5; color: transparent;" spellcheck="false" dir="ltr"><div class="gsfi" style="top: 1px; padding: 0pt; white-space: nowrap; position: absolute; width: 100%; color: silver; z-index: 0; text-align: left; left: 3px;" id="gs_tad0" dir="ltr"></div><div class="gsfi" style="position: absolute; top: 1px; background: none repeat scroll 0% 0% transparent; color: rgb(0, 0, 0); padding: 0pt; white-space: nowrap; z-index: 2; left: 3px;" dir="ltr">aol</div><div style="position: absolute; top: 1px; width: 1px; height: 20px; background-color: rgb(0, 0, 0); padding: 0pt; z-index: 4; left: 14px; visibility: hidden;"></div><div class="gsfi" style="position: absolute; top: 1px; background: none repeat scroll 0% 0% rgb(255, 255, 255); color: rgb(255, 255, 255); padding: 0pt; white-space: nowrap; z-index: 1;"></div></div></td><td><table cellspacing="0" cellpadding="0" style="width: 100%;" dir="ltr"><tbody><tr><td class="gsib_e"><div></div></td><td class="gsib_b" style="color: rgb(161, 185, 237);">×</td><td class="gsib_f"><div></div></td><td class="gsib_d"><div></div></td></tr></tbody></table></td></tr></tbody></table>

Upvotes: 3

Related Questions