-2

(I've removed the old part as it's redundant)

EDIT -

Even without any knowledge of C#, I've tried to convert the code that Lars pointed me to... Managed to get it compiling. And useable from the toolbox. However, It doesn't seem like CueTextBox1.Cue = "Test" works. Again, no error seems to be produced. I've checked and the cue property has been added to properties for the CueTextBox, but changing it doesn't change the cue, or seemingly do anything for that matter. Here's the converted code:

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

Class CueTextBox
    Inherits TextBox
    Public Property Cue() As String
        Get
            Return mCue
        End Get
        Set(value As String)
            mCue = value
            updateCue()
        End Set
    End Property

    Private Sub updateCue()
        If (Me.IsHandleCreated And mCue = Nothing) Then
            SendMessage(Me.Handle, &H1501, New IntPtr(1), mCue)
        End If
    End Sub

    Protected Overrides Sub OnHandleCreated(e As EventArgs)
        MyBase.OnHandleCreated(e)
        updateCue()
    End Sub

    Private mCue As String

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As     Integer, ByVal wp As IntPtr, ByVal lp As String) As IntPtr
    End Function
End Class

As Plutonix suggested, I have changed the last param of the PInvoke Sadly there was no change. Below is the updated block.

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> LParm As String) As IntPtr
    End Function

EDIT2 -

Still getting the same issue as given in the title. Any help would be greatly appreciated. The cue is working in design view, however upon compiling, in certain projects, the cue fails to set.

jackjt8
  • 11
  • 2
  • 1
    The code is nonsense and can neither compile nor be usable. We are not clairvoyants, you'll need to post what you actually try to use. – Hans Passant Mar 12 '15 at 17:13
  • See [Watermark TextBox in WinForms](http://stackoverflow.com/a/4902969/719186) – LarsTech Mar 12 '15 at 17:39
  • Hans Passant, I made it simpler for you as you seemingly can't understand. – jackjt8 Mar 12 '15 at 18:07
  • @jackjt8 what hans meant was that the code as you posted it, doesn't work or even compiles. Now, the code from the answer Lars pointed out is C# (not C++) and it's for a custom control. The answer itself explains how to use it - you don't even need to convert it. – Josh Part Mar 12 '15 at 21:29
  • @Josh Part, Ah well, My mistake for mixing the two up. But I did have to convert it. Since I don't have the ability to create C# classes while doing VB.NET dev. Even then, it's semi-working. It's added as a control, it works like a textbox & it has the que property... but it's not displaying the que banner. – jackjt8 Mar 12 '15 at 22:01
  • @jackjt8 You could also try creating a separate C# user control project, add the code and compile it as a dll, then add it to your VB project as reference. If it works that way and not after convertion, update your question with the converted VB code and maybe we could help you with that now. – Josh Part Mar 13 '15 at 00:11
  • @Josh Part, I will try that now. – jackjt8 Mar 13 '15 at 11:08
  • @Josh Part, I seem to be getting the same issue. It's added the cuetextbox and the cue property is there and can be set. But It just isn't causing any change with the cuetextbox. – jackjt8 Mar 13 '15 at 11:32
  • Try changing the last param for the PInvoke to: ` LParm As String` see http://pinvoke.net/default.aspx/user32/SendMessage.html – Ňɏssa Pøngjǣrdenlarp Mar 13 '15 at 13:06
  • @Plutonix, I've just tried changing it with no luck. I've updated the original post with the new line. – jackjt8 Mar 13 '15 at 17:29
  • change your test in `UpdateCue` to: `If (Me.IsHandleCreated And String.IsNullOrEmpty(mCue) = False) Then` it works fine. I might remove the last part so that you can remove a Cue by passing an empty string – Ňɏssa Pøngjǣrdenlarp Mar 13 '15 at 17:39
  • @Plutonix, Whoops. I completely messed that part up. It's working fine now. I do believe that being able to pass empty strings will be useful, and it seems to work without any issue. Thanks for your help. – jackjt8 Mar 13 '15 at 17:51

1 Answers1

0

Huge thanks to @Plutonix. The fixed and fully working code is as followed. The issue was in updateCue(), mainly with mCue = Nothing. Changing it to String.IsNullOrEmpty(mCue) = False fixes the issue. But as @Plutonix pointed out, Removing the check would allow for empty strings to be passed.

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

Class CueTextBox
    Inherits TextBox
    Public Property Cue() As String
        Get
           Return mCue
        End Get
        Set(value As String)
            mCue = value
            updateCue()
        End Set
    End Property

    Private Sub updateCue()  
        If (Me.IsHandleCreated) Then
            SendMessage(Me.Handle, &H1501, New IntPtr(1), mCue)
        End If
    End Sub

    Protected Overrides Sub OnHandleCreated(e As EventArgs)
        MyBase.OnHandleCreated(e)
        updateCue()
    End Sub

    Private mCue As String

    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> LParm As String) As IntPtr
    End Function
End Class

EDIT - This semi-works. For some reason, the cue still doesn't show up at runtime on certain projects. Leads me to believe there's an issue with these projects. As to what, I don't know.

jackjt8
  • 11
  • 2