Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Gradient Brush Properties (Read 2995 times)
BudMan
YaBB Newbies
*
Offline


Credidi me felem vidisse

Posts: 45
Joined: Jul 14th, 2007
Gradient Brush Properties
Feb 23rd, 2008 at 1:24pm
Print Post  
I am trying to store Style-related properties for calendar items in a database. This is easy for Properties like LineColor and FillColor because I can get their 'ARGB' values. But I cannot figure out how to do this for the Brush property when it is originally set to a LinearGradientBrush. For example, I can set the Brush property with code like the following:

Dim app As New MindFusion.Scheduling.Appointment
Dim argb1 As Int32 = -1 'White
Dim argb2 As Int32 = -16776961 ' Blue
Dim angle As Single = 90

app.Style.Brush = New MindFusion.Drawing.LinearGradientBrush (Color.FromArgb(argb1), Color.FromArgb(argb2), angle)

But if the user changes the Brush settings, I want to retrieve the new colors and angle. How can I get those?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Gradient Brush Properties
Reply #1 - Feb 25th, 2008 at 5:58am
Print Post  
You can use the Serialize(Brush) static method of the Brush class in order to obtain a string representation of any MindFusion.Drawing.Brush object. This method is marked with EditorBrowsable(Never) so it won't show in IntelliSense, yet it can be safely used from code. To restore the Brush object later from its string representation, use the Brush.Deserialize(string) method.

To get the angle of a LinearGradientBrush, use the Angle property. To get the colors initially passed to the brush constructor, use the LinearColors array. It always contains exactly two elements - the start and end color of the brush.

Meppy
  
Back to top
 
IP Logged
 
BudMan
YaBB Newbies
*
Offline


Credidi me felem vidisse

Posts: 45
Joined: Jul 14th, 2007
Re: Gradient Brush Properties
Reply #2 - Feb 26th, 2008 at 1:39pm
Print Post  
That looks good, but I would up going with code like the following that uses the Brush.ToString property:

  Select Case item.Style.Brush.ToString
     Case "Gradient"
        ' Code here to retrieve properties of
        ' LinearGradientBrush settings
     Case "Solid"
        ' Code here to retrieve properties of
        ' Solidrush settings
  End Select
  
Back to top
 
IP Logged
 
BudMan
YaBB Newbies
*
Offline


Credidi me felem vidisse

Posts: 45
Joined: Jul 14th, 2007
Re: Gradient Brush Properties
Reply #3 - Feb 29th, 2008 at 8:08pm
Print Post  
OK,  I give up--serializing the Brush is the only sane way to go. 2 questions:
1) What is the maximum length of the string generated by the Serialize Brush method?

2) What are the last 4 parameters used for in that string when it is a LinearGradientBrush? Take for example this string:

"l:90;#FFE6E6F0;#FFBEBEC8;0;0;0;0;"

I can see the first 4 parameters indicate brush type, angle, color 1, and color 2. But what do the 4 zeroes mean?

Thanks
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Gradient Brush Properties
Reply #4 - Mar 4th, 2008 at 5:01am
Print Post  
Serializing the brush is the best solution indeed. This way you don't have to worry about the brush type and serializing individual brush properties. As for the last four zeros in the brush's string representation, they are as follows:

1. The number of elements in the Factors array of the brush's Blend property.
2. The number of elements in the Positions array of the brush's Blend property.
3. The number of elements in the Colors array of the brush's InterpolationColors property.
4. The number of elements in the Positions array of the brush's InterpolationColors property.

If there are any elements in these arrays, there are more entries following each number.

Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint