2017-02-10 5 views
0

ウォーターマークのTextBoxを作成するには?

エラーがこの行に起こる......私はWatermark TextBox in WinFormsのコードが見つかりましたが、それはC#バージョンであるので、私はVBのバージョンにコードを変換するためにhttp://converter.telerik.com/を使用しますが、私はまだエラーを取得: -

私はそれを修正するにはどうすればよい

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

エラーメッセージ:BC30311タイプ「整数」の値を「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 

答えて

1

SendMessageためのVB.Netで右の署名があるPInvoke.netによると:

とにかく
<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 

、問題は、この行である:

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

は、それを交換してくださいby:

SendMessage(Me.Handle, &H1501, New IntPtr(1)), mCue) 
+0

ありがとう、問題解決済み – vbnewbie

関連する問題