1

I tried using the following code to set cue banner for a kryptontextbox

Imports System.Runtime.InteropServices

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
       SetCueText(KryptonTextBox1.Handle, "Enter Name here")
    End Sub
End Class

Public Module CueBannerText
    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
    End Function
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
    Private Const EM_SETCUEBANNER As Integer = &H1501

    Public Sub SetCueText(hWnd As IntPtr, text As String)
      if Not hWnd = IntPtr.Zero Then
         SendMessage(hWnd, EM_SETCUEBANNER, 0, text)
      End If
    End Sub
End Module

however, the text is not getting set. how do i fix this

Smith
  • 5,765
  • 17
  • 102
  • 161
  • Its `MultiLine` should set to `false`. And also it should be derived from `TextBox`. As an alternative solution you can paint the show the watermark using a `NativeWindow` by handling `WM_PAINT` message. – Reza Aghaei Nov 18 '16 at 09:15

1 Answers1

2

EM_SETCUEBANNER is applicable on a TextBox control. KryptonTextBox in fact is a composite Control which contains a TextBox.

The TextBox is exposed using a TextBox property. You can use KryptonTextBox1.TextBox.Handle to send EM_SETCUEBANNER message.

To see the source code for components take a look at this GitHub repository. Here is a related part of code:

public class KryptonTextBox : VisualControlBase, IContainedInputControl
{
    //...
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Browsable(false)]
    public TextBox TextBox
    {
        get { return _textBox; }
    }
    //...
}
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • Thank you for your compliments :) Feel free to notify me when you need more attention to a question. If I have anything to share I'll share. Taking benefit from the whole community is better than just one :) – Reza Aghaei Nov 20 '16 at 09:55