Results 1 to 3 of 3

Thread: Overlaying text on a textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    6

    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

  2. #2
    Addicted Member Cristian's Avatar
    Join Date
    Jun 2006
    Posts
    228

    Smile 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

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Overlaying text on a textbox

    I think this is what you are looking for:
    http://www.eggheadcafe.com/software/...k-not-asp.aspx
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width