0

I found the code in Watermark TextBox in WinForms but it is C# version, so I use http://converter.telerik.com/ to convert the code to VB version, but I still get error......

Error happen on this line:-

SendMessage(Me.Handle, &H1501, DirectCast(1, IntPtr), mCue)

How can I fix it?

ERROR MESSAGE: BC30311 Value of type 'Integer' cannot be converted to 'IntPtr'.

Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Class CueTextBox
    Inherits TextBox
    <Localizable(True)> _
    Public Property Cue() As String
        Get
            Return mCue
        End Get
        Set
            mCue = value
            updateCue()
        End Set
    End Property

    Private Sub updateCue()
        If Me.IsHandleCreated AndAlso mCue IsNot Nothing Then
            SendMessage(Me.Handle, &H1501, DirectCast(1, IntPtr), mCue)   'this line get the error msg
        End If
    End Sub
    Protected Overrides Sub OnHandleCreated(e As EventArgs)
        MyBase.OnHandleCreated(e)
        updateCue()
    End Sub
    Private mCue As String

    ' PInvoke
    <DllImport("user32.dll", CharSet := CharSet.Unicode)> _
    Private Shared Function SendMessage(hWnd As IntPtr, msg As Integer, wp As IntPtr, lp As String) As IntPtr
    End Function
End Class
Community
  • 1
  • 1
vbnewbie
  • 206
  • 6
  • 26

1 Answers1

1

According to PInvoke.net the right signature in VB.Net for SendMessage is :

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function

Anyway, the problem is in this line:

SendMessage(Me.Handle, &H1501, DirectCast(1, IntPtr), mCue)  

Try to replace it by:

SendMessage(Me.Handle, &H1501, New IntPtr(1)), mCue)  
Pikoh
  • 7,582
  • 28
  • 53