
Custom Painting in an inherited textbox control
The following works for me:
Public Class tt
Inherits TextBox
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Blue,
ButtonBorderStyle.Solid)
MyBase.OnPaint(e)
End Sub
End Class
--
Jacob Grass
Microsoft .NET MVP
Quote:
> I found this in the documentation. Does this mean that I am not able to
> accomplish this?
> Note Some Windows Forms controls, such as TextBox, are painted
directly
> by Windows. In these instances, the OnPaint method is never called, and
thus
> the above example will never be called.
> Scott
> > Your custom control inherits from textbox? Use the following instead:
> > Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
> > e.Graphics.DrawLine(System.Drawing.Pens.Black, 5, 5, 300, 100)
> > MyBase.OnPaint(e)
> > End Sub
> > --
> > Jacob Grass
> > Microsoft .NET MVP
> > > I need to be able to display greyed out text as the background of an
> > > inherited textbox control. Once the user typed something in, I need
to
> > > clear the background of the textbox. I know that custom drawing can
be
> > > accomplished with a form control by handling the Mybase.Paint event as
> > > listed below. This does not seem to work with a usercontrol which
> > inherits
> > > from the TextBox class. Why??
> > > Private Sub Pnt(ByVal sender As Object, ByVal e As PaintEventArgs)
> Handles
> > > mybase.Paint
> > > e.Graphics.DrawLine(System.Drawing.Pens.Black, 5, 5, 300, 100)
> > > End Sub
> > > Thanks in advance