C
CroDude
I've made a custom groupbox control. Inside, as one of it's members is
CSimpleGradient object. CSimpleGradient is a wrapper class for gradient
usage. Basically it looks like that:
[TypeConverter(typeof(CSimpleGradientConverter))]
public class CSimpleGradient
{
private float m_GradientAngle;
private Color m_ColorA;
private Color m_ColorB;
// Properties
blah blah ...
// Constructor
public CSimpleGradient(float _angle, Color _colorA, Color _colorB)
{
this.m_ColorA = _colorA;
this.m_ColorB = _colorB;
this.m_GradientAngle = _angle;
}
#endregion
}
It uses custom type converter(ExpandableObjectConverter). It's code goes
like this:
internal class CSimpleGradientConverter : ExpandableObjectConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type
sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
// Overrides the ConvertFrom method of TypeConverter.
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is string)
{
string[] v = ((string)value).Split(new char[] {','});
float angle = float.Parse(v[0]);
Color colorA = Color.FromName(v[1].Trim());
Color colorB = Color.FromName(v[2].Trim());
return new CSimpleGradient(angle, colorA, colorB);
}
return base.ConvertFrom(context, culture, value);
}
// Overrides the ConvertTo method of TypeConverter.
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo
culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
return ((CSimpleGradient)value).Angle + "," +
((CSimpleGradient)value).ColorA + "," + ((CSimpleGradient)value).ColorB;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
In my custom group-box class, CSimpleGradient properties looks like this:
[Category("Appearance_Header"), Description("Gets/Sets header gradient color
fill/gradient angle if HeaderFillType is set to Gradient."),
RefreshProperties(RefreshProperties.All),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public CSimpleGradient HeaderGradientColor
{
get{return this.m_HeaderGradient;}
set
{
this.m_HeaderGradient = value;
this.Invalidate();
}
Everything works fine, but after changing values of CSimpleGradent object I
have to ALT+TAB forth and back to designer editor for changes to be
repainted.
I'm not sure why it doesn't work automatically since there is Invalidate
call in property's SET.
Please help! Thanks in advance!
D.
CSimpleGradient object. CSimpleGradient is a wrapper class for gradient
usage. Basically it looks like that:
[TypeConverter(typeof(CSimpleGradientConverter))]
public class CSimpleGradient
{
private float m_GradientAngle;
private Color m_ColorA;
private Color m_ColorB;
// Properties
blah blah ...
// Constructor
public CSimpleGradient(float _angle, Color _colorA, Color _colorB)
{
this.m_ColorA = _colorA;
this.m_ColorB = _colorB;
this.m_GradientAngle = _angle;
}
#endregion
}
It uses custom type converter(ExpandableObjectConverter). It's code goes
like this:
internal class CSimpleGradientConverter : ExpandableObjectConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type
sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
// Overrides the ConvertFrom method of TypeConverter.
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is string)
{
string[] v = ((string)value).Split(new char[] {','});
float angle = float.Parse(v[0]);
Color colorA = Color.FromName(v[1].Trim());
Color colorB = Color.FromName(v[2].Trim());
return new CSimpleGradient(angle, colorA, colorB);
}
return base.ConvertFrom(context, culture, value);
}
// Overrides the ConvertTo method of TypeConverter.
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo
culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
return ((CSimpleGradient)value).Angle + "," +
((CSimpleGradient)value).ColorA + "," + ((CSimpleGradient)value).ColorB;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
In my custom group-box class, CSimpleGradient properties looks like this:
[Category("Appearance_Header"), Description("Gets/Sets header gradient color
fill/gradient angle if HeaderFillType is set to Gradient."),
RefreshProperties(RefreshProperties.All),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public CSimpleGradient HeaderGradientColor
{
get{return this.m_HeaderGradient;}
set
{
this.m_HeaderGradient = value;
this.Invalidate();
}
Everything works fine, but after changing values of CSimpleGradent object I
have to ALT+TAB forth and back to designer editor for changes to be
repainted.
I'm not sure why it doesn't work automatically since there is Invalidate
call in property's SET.
Please help! Thanks in advance!
D.