EM_SETCUEBANNER sendmessage vb.net usercontrol not working

微笑、不失礼 提交于 2021-01-28 20:08:56

问题


If I use the code shown below on a vb.net winform the cue banner / watermark appears and behaves as expected (Win7 Pro 32bit VS2008 & 64bit VS2010). However when using the same style of code in a vb.net usercontrol the watermark is not displayed. Anyone got any clues?

Some hours later... This is looking like PEBKAC. Works in a test app. with user controls. Both those created at design time and those loaded at run-time, still doesn't work in the main app. though. Still puzzled. Still looking for a clue.

' 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:


Not so much PEBKAC as yet another instance of M$ not documenting things as well as they might.

The short answer is to call Application.EnableVisualStyles() before the Run method.

Application.EnableVisualStyles()
Application.Run()

See questions/7518894/sendmessage-doesnt-work-in-one-project on this site for more info.



来源:https://stackoverflow.com/questions/13545181/em-setcuebanner-sendmessage-vb-net-usercontrol-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!