Results 1 to 7 of 7

Thread: Text not repainting on custom textbox

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Text not repainting on custom textbox

    I for the life of me, can not figure out how to get the text to repaint over my background. When the paint event fires, all text disappears.

    VB.Net Code:
    1. Imports System.ComponentModel
    2.  
    3. Public Class UserControl1
    4.     Inherits TextBox
    5.     Private pic As Image
    6.     Sub New()
    7.  
    8.         ' This call is required by the Windows Form Designer.
    9.         InitializeComponent()
    10.  
    11.         ' Add any initialization after the InitializeComponent() call.
    12.         SetStyle(ControlStyles.UserPaint, True)
    13.     End Sub
    14.     Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
    15.  
    16.         If Char.IsNumber(e.KeyChar) = False Then
    17.             e.Handled = True
    18.         End If
    19.     End Sub
    20.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    21.  
    22.         MyBase.OnPaint(e)
    23.  
    24.         e.Graphics.DrawImage(pic, 0, 0, 32, 32)
    25.  
    26.     End Sub
    27.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
    28.     Description("Select a icon for the textbox."), _
    29.     Browsable(True)> _
    30.     Public Property Picture() As Image
    31.         Get
    32.             Return pic
    33.         End Get
    34.         Set(ByVal value As Image)
    35.             pic = value
    36.             Me.Invalidate()
    37.         End Set
    38.     End Property
    39.  
    40. End Class

    Any help is appreciated.
    Last edited by zalez; Oct 19th, 2009 at 09:41 PM.

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