Custom Painting in an inherited textbox control 
Author Message
 Custom Painting in an inherited textbox control

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



Mon, 03 May 2004 03:20:36 GMT  
 Custom Painting in an inherited textbox control
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


Quote:
> 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



Mon, 03 May 2004 03:34:05 GMT  
 Custom Painting in an inherited textbox control
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



Quote:
> 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



Mon, 03 May 2004 05:30:53 GMT  
 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



Tue, 04 May 2004 00:33:11 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. custom form control: Cannot view design view of forms that inherit this form

2. User control or inherit to make custom button?

3. Custom Inherited User Control Doesn't Show Up in Toolbox

4. Inheriting TextBox control

5. Help with Inheriting a TextBox Winforms Control

6. Any way to make a custom control paint past edge of container

7. Any way to make a custom control paint past edge of container

8. Custom inherited class...

9. custom paint event for checkbox

10. Help: Custom TextBox and ComboBox control issue

11. Printing with Rich TextBox custom control

12. Custom Control Textbox

 

 
Powered by phpBB® Forum Software