Results 1 to 7 of 7

Thread: Text not repainting on custom textbox

  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.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Text not repainting on custom textbox

    You are calling the base paint event which draws the text, then you are calling draw image, which will draw over the text. You need to draw the text after you draw your image in the background.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: Text not repainting on custom textbox

    Thanks for your reply Neg. I am not quite following what you are saying. I tried using the OnPaintBackGround override also with the same result. The text types out fine but when I drag the form off screen then back the text disappears. The text will reappear if I arrow back to the beginning of the textbox and start typing again.

  4. #4
    Addicted Member garyjohn_2000's Avatar
    Join Date
    Apr 2005
    Location
    Timbaland
    Posts
    243

    Re: Text not repainting on custom textbox

    nvm wat i posted....still figuring....
    Last edited by garyjohn_2000; Oct 20th, 2009 at 02:20 AM. Reason: corrected


    Anyone who has never made a mistake has never tried anything new. - Einstein
    Peace!

  5. #5
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Text not repainting on custom textbox

    From googling I found that a few people mention that BackgroundImages are not supported by a TextBox (even if you draw them manually). I'm not sure if we can use API's or something to get around it...

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: Text not repainting on custom textbox

    Quote Originally Posted by NickThissen View Post
    From googling I found that Na few people mention that BackgroundImages are not supported by a TextBox (even if you draw them manually). I'm not sure if we can use API's or something to get around it...
    Not supported as in it will not draw or it just doesn't work right?

  7. #7

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