System.Windows.Forms.TextBox中的水印

时间:2021-03-17 15:50:55

What is he best way to implement Watermark functionality for a System.Windows.Forms.TextBox in .Net 2.0 with C#?

使用C#在.Net 2.0中为System.Windows.Forms.TextBox实现Watermark功能的最佳方法是什么?


Edit:

Using the ready-made component from CodeProject was very easy. It's also with a The Code Project Open License (CPOL).

使用CodeProject中的现成组件非常简单。它还带有代码项目开放许可证(CPOL)。

2 个解决方案

#1


15  

lately I needed a watermark textbox, the first thing that popped in to my head was OnLeave and OnEnter events of textbox, but first I googled it and I got two links first was the one in CodeProject which used the System.Drawing namespace and the other one was here using the SendMessage() over here http://vidmar.net/weblog/archive/2008/11/05/watermarked-textbox-in-windows-forms-on-.net.aspx.

最近我需要一个水印文本框,首先出现在我脑海中的是文本框的OnLeave和OnEnter事件,但首先我用谷歌搜索它,我首先得到两个链接是CodeProject中的一个使用System.Drawing命名空间和另一个一个人在这里使用SendMessage()在这里http://vidmar.net/weblog/archive/2008/11/05/watermarked-textbox-in-windows-forms-on-.net.aspx。

I beleive the SendMessage one is much easier and it also has no flickering in it. though I used it.

我相信SendMessage更简单,它也没有闪烁。虽然我用过它。

I hope it will be helpful for you.

我希望它对你有所帮助。

#2


7  

It is not as straightforward as one would think. You need to use using the System.Drawing namespace and override the OnPaint event.

它并不像人们想象的那么简单。您需要使用System.Drawing命名空间并覆盖OnPaint事件。

Here are some links of some people that have already done it.

以下是一些已经完成此操作的人的链接。

Link & Link

链接和链接

#1


15  

lately I needed a watermark textbox, the first thing that popped in to my head was OnLeave and OnEnter events of textbox, but first I googled it and I got two links first was the one in CodeProject which used the System.Drawing namespace and the other one was here using the SendMessage() over here http://vidmar.net/weblog/archive/2008/11/05/watermarked-textbox-in-windows-forms-on-.net.aspx.

最近我需要一个水印文本框,首先出现在我脑海中的是文本框的OnLeave和OnEnter事件,但首先我用谷歌搜索它,我首先得到两个链接是CodeProject中的一个使用System.Drawing命名空间和另一个一个人在这里使用SendMessage()在这里http://vidmar.net/weblog/archive/2008/11/05/watermarked-textbox-in-windows-forms-on-.net.aspx。

I beleive the SendMessage one is much easier and it also has no flickering in it. though I used it.

我相信SendMessage更简单,它也没有闪烁。虽然我用过它。

I hope it will be helpful for you.

我希望它对你有所帮助。

#2


7  

It is not as straightforward as one would think. You need to use using the System.Drawing namespace and override the OnPaint event.

它并不像人们想象的那么简单。您需要使用System.Drawing命名空间并覆盖OnPaint事件。

Here are some links of some people that have already done it.

以下是一些已经完成此操作的人的链接。

Link & Link

链接和链接