Custom Control Text Paint

N

Nathan Carroll

The following works but would it make any sense to paint within the
TextChanged procedure instead and if how do I get at control graphics from
there?

Protected Overrides Sub OnPaint(ByVal pe As
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(pe)

ControlPaint.DrawBorder3D( _
pe.Graphics, _
Me.ClientRectangle, _
Border3DStyle.Sunken)

Dim fnt As New Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Point)
pe.Graphics.DrawString(Me.Text, fnt, Brushes.Black, 0, 0)

End Sub

Private Sub datetimepicker_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles MyBase.TextChanged

Me.Invalidate()
'repaint it here
'or force repaint

End Sub
 
C

Claes Bergefall

No, it wouldn't make any sense. The code in OnPaint is necessary
so you would have duplicate code or a broken control

The code is correct as it is now

/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top