EM_SETCUEBANNER sendmessage vb.net usercontrol无法正常工作

时间:2012-11-24 20:16:28

标签: user-controls sendmessage

如果我在vb.net winform上使用下面显示的代码,则会出现cue banner / watermark并且行为与预期一致(Win7 Pro 32bit VS2008& 64bit VS2010)。但是,在vb.net usercontrol中使用相同样式的代码时,不会显示水印。有人有任何线索吗?

几个小时后......这看起来像是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

1 个答案:

答案 0 :(得分:2)

PEBKAC与M $的另一个实例不同,它不会记录事情。

简短的回答是在Run方法之前调用Application.EnableVisualStyles()。

Application.EnableVisualStyles()
Application.Run()

有关详细信息,请参阅本网站上的问题/ 7518894 / sendmessage-doesnt-work-in-one-project。