Overlaying text on a textbox
I need to overlay the word 'VOID' over a textbox but in a semi transparent way so the text in the textbox underneath 'VOID' can still be seen.
I have tried using various controls with no luck and there is no paint event for the textbox.
I am open to any way this can be done including not so elegent solutions.
Thanks
Re: Overlaying text on a textbox
Although the textbox doesn't have a paint event i'd found a solution.
All you paint code must be done inside the Draw Sub.
The code inside the Draw sub is just a example.
Code:
DebuggerDisplay("Name = {Name} Text = {Text}")> _
Public Class TextBoxEnabledColor
Inherits TextBox
Const WM_PAINT = &HF
<System.Diagnostics.DebuggerStepThrough()> _
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = WM_PAINT Then
Draw()
End If
End If
End Sub
Private Sub Draw()
Dim RctControl As Rectangle
Dim StfControl As StringFormat = New StringFormat
Dim GrpControl As Graphics
GrpControl = Graphics.FromHwnd(Me.Handle)
GrpControl.FillRectangle(Brushes.White, Me.DisplayRectangle)
If Me.TextAlign = HorizontalAlignment.Right Then
StfControl.Alignment = StringAlignment.Far
GrpControl.DrawString(Me.Text, Me.Font, Brushes.Black, Me.DisplayRectangle.Right, 1, StfControl)
Else
StfControl.Alignment = StringAlignment.Near
GrpControl.DrawString(Me.Text, Me.Font, Brushes.Black, Me.DisplayRectangle.Left, 1, StfControl)
End If
End Sub
End Class
Re: Overlaying text on a textbox