在我的 Windows 应用程序中,我想X
在文本框的右边缘放置一个以清除它。类似于谷歌现在使用的。查看谷歌并搜索任何内容。X
一旦您开始输入内容,您就会在文本框中看到。
我知道只要在文本框旁边放一个按钮就可以了。但我想做一些更好的事情。
在我的 Windows 应用程序中,我想X
在文本框的右边缘放置一个以清除它。类似于谷歌现在使用的。查看谷歌并搜索任何内容。X
一旦您开始输入内容,您就会在文本框中看到。
我知道只要在文本框旁边放一个按钮就可以了。但我想做一些更好的事情。
谁说谷歌在文本框的右端放了一个 X....??
那不在谷歌搜索文本框中。它在那个文本框之外。这就是你能做到的唯一方法。谷歌使用一个表格,其中一个 td 包含文本框,而另一个包含“X”。他们放了一些 css,让你感觉 X 在文本框中。Whixh真的不是。
这是谷歌搜索文本框的html:
<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("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D") 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>
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.
嗯,对不起,伙计,但在我看来,你只能通过添加一个按钮(甚至在文本框内)来做到这一点,并将其设置为当它被点击时它会清除文本框
textbox.Clear();
祝你好运,祝你好运