Brush and control.forecolor Question

  • Thread starter Thread starter jcrouse
  • Start date Start date
J

jcrouse

I have the following string:

e.Graphics.DrawString(Label5.Text, lblP1B1.Font, Brushes.White, -y, 0)

I want to use the property label.forecolor for my text color. How do I get
whats in label.forecolor into the Brushes.Color parameter?

Thank you,
John
 
John,

Create a new brush with something like:

<code (VB.NET) >
Dim aBrush As New SolidBrush(Me.Label1.ForeColor)
graphics.DrawString("This is a test", Me.Label1.Font, aBrush, 10, 10)
</code>

-Sam Matzen
 
John,
As Samuel suggested, create a new brush, I would be certain to Dispose of
the brush when you were done.

Something like:
Dim aBrush As New SolidBrush(Me.Label1.ForeColor)
graphics.DrawString("This is a test", Me.Label1.Font, aBrush, 10, 10)
aBrush.Dispose()

Rather then create & dispose of the brush in the paint event itself, I would
consider disposing of the old one & creating a new one in the ForeColor
property Get.

Something like:

Private m_brush As SolidBrush

Public Overrides Property ForColor As Color
Get
Return MyBase.Color
End Get
Set(ByVal value As Color)
m_brush.Dispose()
m_brush = New SolidBrush(value)
MyBase.ForeColor = value
End Set
End Property

Hope this helps
Jay
 
Back
Top