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:
Imports System.ComponentModel
Public Class UserControl1
Inherits TextBox
Private pic As Image
Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
SetStyle(ControlStyles.UserPaint, True)
End Sub
Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
If Char.IsNumber(e.KeyChar) = False Then
e.Handled = True
End If
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.DrawImage(pic, 0, 0, 32, 32)
End Sub
<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
Description("Select a icon for the textbox."), _
Browsable(True)> _
Public Property Picture() As Image
Get
Return pic
End Get
Set(ByVal value As Image)
pic = value
Me.Invalidate()
End Set
End Property
End Class
Any help is appreciated.
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.
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.
Re: Text not repainting on custom textbox
nvm wat i posted....still figuring....
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...
Re: Text not repainting on custom textbox
Quote:
Originally Posted by
NickThissen
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?
Re: Text not repainting on custom textbox
It will draw, but the text will not draw properly as you have seen for yourself.