LinearGradientMode

  • Thread starter Thread starter 101
  • Start date Start date
1

101

Taking a VB .NET course that asked for me to create a gradient listbox, I created the brush like this:

Dim brGrad As New System.Drawing.Drawing2D.LinearGradientBrush( _
rct, _
Color.FromName(cboFromColor.Text), _
Color.FromName(cboToColor.Text), _
(CType(System.Enum.Parse( _
GetType(Drawing2D.LinearGradientMode), _
strGradient), Drawing2D.LinearGradientMode)))

They wrote it basically like this:

Dim brGrad As New System.Drawing.Drawing2D.LinearGradientBrush( _
rct, _
Color.FromName(cboFromColor.Text), _
Color.FromName(cboToColor.Text), _
(CType(System.Enum.Parse( _
GetType(Drawing2D.HatchStyle), _
strGradient), Drawing2D.LinearGradientMode)))

Both appear to give the same result. I am ASS U ME ing that that theirs worked because both are enumeratons in the drawing2 namespace that take the same type of argument.

How far off am I? Is mine the proper way to do it or did I miss something?
 
101 said:
Taking a VB .NET course that asked for me to create a gradient
listbox, I created the brush like this:
Dim brGrad As New System.Drawing.Drawing2D.LinearGradientBrush( _
rct, _
Color.FromName(cboFromColor.Text), _
Color.FromName(cboToColor.Text), _
(CType(System.Enum.Parse( _
GetType(Drawing2D.LinearGradientMode), _
strGradient), Drawing2D.LinearGradientMode)))

They wrote it basically like this:

Dim brGrad As New System.Drawing.Drawing2D.LinearGradientBrush( _
rct, _
Color.FromName(cboFromColor.Text), _
Color.FromName(cboToColor.Text), _
(CType(System.Enum.Parse( _
GetType(Drawing2D.HatchStyle), _
strGradient), Drawing2D.LinearGradientMode)))

Both appear to give the same result. I am ASS U ME ing that that
theirs worked because both are enumeratons in the drawing2 namespace
that take the same type of argument.
How far off am I? Is mine the proper way to do it or did I miss
something?

I would say that your method is correct, and theirs works only by
'coincidence' in that the four enum members of LinearGradientMode have
the same integer values as the enum members of HatchStyle with the same
respective names (ie LGM.Horizonal = 0 = HS.Horizontal and so on). This
isn't really a real coincidence I suspect, but nonetheless it shouldn't
be relied upon.

Unless of course strGradient is also used elsewhere to create a
HatchStyle, im which case... I suppose it's OK if it's documented.
 

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

Back
Top