Resolved Making A Visible But Gray Informational Label Inside A Multiline TextBox That Can Be Typed Over

zunebuggy65

Active member
Joined
Oct 12, 2023
Messages
42
Programming Experience
3-5
I have a multiline TextBox on my form and I added a Label in the center of the textbox and made the Label text gray and programmatically set Label1.BackColor = System.Drawing.Color.Transparent

What I want is just to add a label that simply states "Type text or drag text here". I have that but if I type to the point where the text comes to the Label, the typed or pasted text goes behind the Label and the label is in no way transparent.

I was pretty sure I could do this in VB 6 but I cannot remember how, and I have tried all the Properties I can think of in VB.net. Maybe Label is the wrong control? Can anyone help?

Thank you
 
I added this code to the form. It compiles without errors, but no text is displayed.

VB.NET:
Imports System.Runtime.InteropServices
Public Class frm_Main
    Private Const EM_SETCUEBANNER As Integer = &H1501
    <DllImport("user32.dll", CharSet:=CharSet.Auto)>
    Private Shared 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 Sub SetCueText(ByVal control As Control, ByVal text As String)
        SendMessage(control.Handle, EM_SETCUEBANNER, 0, text)
    End Sub

    Private Sub frm_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetCueText(TextBox1, "Type message or drag or paste text here.")
    End Sub

End Class
 
This is what the textbox looks like on the form, the text in the background disappears when the textbox gets focus.

Screenshot 2023-10-13 140026.png
Screenshot 2023-10-13 140037.png
 
With this code?

1697224656277.png
 
OK, I think I may have misunderstood post #8 and possibly post #7. In post #7, are you simply reporting the behaviour that matches your requirements or are you saying that it's not working as expected?
 
Back
Top