如果我在 vb.net winform 上使用下面显示的代码,则会出现提示横幅/水印并按预期运行(Win7 Pro 32 位 VS2008 和 64 位 VS2010)。但是,当在 vb.net 用户控件中使用相同样式的代码时,不会显示水印。有人有任何线索吗?
几个小时后......这看起来像PEBKAC。在测试应用程序中工作。与用户控件。在设计时创建的和在运行时加载的,仍然不能在主应用程序中工作。尽管。还是很疑惑。还在寻找线索。
' Call from form / usercontrol load event handler.
Userhint.WatermarkSet(textbox1, "Some arbitrary text.")
' Noddy library class.
Friend Class Userhint
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal Msg As UInteger, _
ByVal wParam As IntPtr, _
ByVal lParam As String) As IntPtr
End Function
Public Shared Sub WatermarkSet(ByVal ctl As Control, _
byval hintText as string)
const EM_SETCUEBANNER as int32 = &h1501
dim retainOnFocus As IntPtr = new IntPtr(1)
SendMessage(New HandleRef(ctl, ctl.Handle), _
EM_SETCUEBANNER, _
retainOnFocus, _
hintText)
End sub
End Class