473,378 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Control doesn't repaint when using object with custom type converter

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(DesignerSerializat ionVisibility.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.
Nov 17 '05 #1
4 2549
Problem could be related to how Windows posts messages

As SDK help says

Calling the Invalidate method does not force a synchronous paint; to force a
synchronous paint, call the Update method after calling the Invalidate
method. When this method is called with no parameters, the entire client
area is added to the update region

Are you looking for synchronous paint?

HTH
Alex

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:db**********@news1.xnet.hr...
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(DesignerSerializat ionVisibility.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.

Nov 17 '05 #2
Thanks Alex for help, but that didn't fix it.

I just want to repaint the control when HeaderGradientColor property changes
either from within DesignView or through the code.
It is so strange since all other properties are repainting correctly in
DesignView when using Invalidate in Set method.
All these(working) are standard types such as int, float, color etc. this
happens only with that custom one(CSimpleGradient).
Reallly strange!


Nov 17 '05 #3
Invalidate should post wm_paint. Update should call Paint.
You can try to find out what is going in with some profiler or just by
monitoring what you get in message loop.

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:db**********@news1.xnet.hr...
Thanks Alex for help, but that didn't fix it.

I just want to repaint the control when HeaderGradientColor property changes either from within DesignView or through the code.
It is so strange since all other properties are repainting correctly in
DesignView when using Invalidate in Set method.
All these(working) are standard types such as int, float, color etc. this
happens only with that custom one(CSimpleGradient).
Reallly strange!

Nov 17 '05 #4
I found the solution ... You must invalidate through the designer object.
Here it goes:

public override void Initialize(IComponent component)
{
base.Initialize(component);
// Record instance of control we're designing
this.m_GroupBox = (CDizzyGroupBox) component;
// Hook up events
ISelectionService s = (ISelectionService)
GetService(typeof(ISelectionService));
IComponentChangeService c = (IComponentChangeService)
GetService(typeof(IComponentChangeService));
s.SelectionChanged += new EventHandler(OnSelectionChanged);
c.ComponentRemoving += new ComponentEventHandler(OnComponentRemoving);
c.ComponentChanged+=new ComponentChangedEventHandler(OnComponentChanged);
}

private void OnComponentChanged(object sender, ComponentChangedEventArgs e)
{
this.m_GroupBox.Update();
this.m_GroupBox.Invalidate();
}

protected override void Dispose(bool disposing)
{
ISelectionService s = (ISelectionService)
GetService(typeof(ISelectionService));
IComponentChangeService c = (IComponentChangeService)
GetService(typeof(IComponentChangeService));
// Unhook events
s.SelectionChanged -= new EventHandler(OnSelectionChanged);
c.ComponentRemoving -= new ComponentEventHandler(OnComponentRemoving);
c.ComponentChanged -= new ComponentChangedEventHandler(OnComponentChanged);
base.Dispose(disposing);
}
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alien | last post by:
I have a hex editor-type class that extends UserControl and paints its data to a PictureBox. Basically the problem is that repainting it takes usually between 60 and 80ms, which may seem pretty...
0
by: Tom | last post by:
I am developing a page that will contain multiple instances of a Composite Custom Control that i have developed. The problem is that the user will determine at run time how many of the control...
3
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects...
20
by: BB | last post by:
Hello all, I am trying to override OnPaint in a custom textbox control (so I can drawstring a caption, etc.). In the code below, I get the "painting the form" message as expected, but not the...
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
2
by: Radu | last post by:
Hi. I am creating a user control in vs2005 which is supposed to provide a fancy gradient background - in theory, you just drop it on a form, you set the start/end colors, the gradient type, and...
1
by: --== Alain ==-- | last post by:
Hi, I finally found how to update the render of my custom control when one of its property value changed. However, i would like to know if there is not another way, because i'm afraid about...
0
by: philaphan80 | last post by:
Is there a way to force the Visual Studio IDE (Page Control at design- time) to refresh / repaint itself upon drag & drop of *any* item from the toolbox? Perhaps a method I need to override within...
2
by: R.A.F. | last post by:
Hi, I have a custom control in which i have a collection property named "Columns". this collection property add/remove column objects. in my Column class i have a property named Alignment...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.