Custom design-time control color issues...

P

PeterB

Hello everyone!

I am creating a custom label that could be used in VS design time. I am
inheriting from Control and do all of my drawing myself. I can add a label
to a design form in VS, resize it, change colors (back and fore), change the
font and of course the text. It all looks fine on the VS IDE design form.

The problem is that the code, that reflect the color/font changes, is not
applied to the InitializeComponent method, so if if I close VS and open it
again, the label is reset to it's original color/font values.

Any help here would be greatly appreciated!

/ Peter


Some more info:
I am overriding ForeColor and BackColor

In my control I use the following members to save the color information:
private Color m_backColor = Color.White; //Color.Empty;
private Color m_foreColor = Color.Black;

I then have 2 overridden properties (1 shown)
/// <summary>
/// Gets or sets the background color for the control.
/// </summary>
#if DESIGN
[
Category("Appearance"),
Description("The background color used to display text in the SIB control.")
]
#endif
public override Color BackColor
{
get
{
if ((m_backColor == Color.Empty) && (this.Parent != null))
{
return Parent.BackColor;
}
return m_backColor;
}
set
{
m_backColor = value;
this.Invalidate();
}
}
 
G

Guest

Try to add the follwoing:

#if DESIGN
public bool ShouldSerializeBackColor()
{
return (backColor != Color.Empty);
}
public override void ResetBackColor()
{
BackColor = Color.Empty;
}
#endif

HTH... Alex
 
P

PeterB

Ah... thanks, that saved me some hair...

I suspect it would be easier to create design time controls in the CF if
you'd done it in the full framework and know all the twist and turns :)

I also found that the old site doesn't work anymore:
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/customctrlscompactfx.asp?frame=true -
NOT WORKING

It has been replaced by a new custom graph control:
http://msdn.microsoft.com/library/d...ngcustomcontrolforsmartdeviceapplications.asp

Another usefull link:
http://www.intelliprog.com/articles/index.html

Adding Icon:
http://groups.google.com/groups?hl=...soft.public.dotnet.framework.compactframework

Thanks again!

/ Peter


Alex Yakhnin said:
Try to add the follwoing:

#if DESIGN
public bool ShouldSerializeBackColor()
{
return (backColor != Color.Empty);
}
public override void ResetBackColor()
{
BackColor = Color.Empty;
}
#endif

HTH... Alex
--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org

PeterB said:
Hello everyone!

I am creating a custom label that could be used in VS design time. I am
inheriting from Control and do all of my drawing myself. I can add a
label
to a design form in VS, resize it, change colors (back and fore), change
the
font and of course the text. It all looks fine on the VS IDE design form.

The problem is that the code, that reflect the color/font changes, is not
applied to the InitializeComponent method, so if if I close VS and open
it
again, the label is reset to it's original color/font values.

Any help here would be greatly appreciated!

/ Peter


Some more info:
I am overriding ForeColor and BackColor

In my control I use the following members to save the color information:
private Color m_backColor = Color.White; //Color.Empty;
private Color m_foreColor = Color.Black;

I then have 2 overridden properties (1 shown)
/// <summary>
/// Gets or sets the background color for the control.
/// </summary>
#if DESIGN
[
Category("Appearance"),
Description("The background color used to display text in the SIB
control.")
]
#endif
public override Color BackColor
{
get
{
if ((m_backColor == Color.Empty) && (this.Parent != null))
{
return Parent.BackColor;
}
return m_backColor;
}
set
{
m_backColor = value;
this.Invalidate();
}
}
 
P

PeterB

Hello again!

I now have the same problem with the BackgroundImage property. I am
inheriting from Control, which also has a BackgroundImage property in the
full framework so I need to add an override in the design version of the
property. My suggestion is:

/// <summary>
/// Property for the background image to be drawn behind the button text.
/// </summary>
#if DESIGN
public override Image BackgroundImage
#else
public Image BackgroundImage
#endif
{
get
{
return this.m_bmpBackgroundImage;
}
set
{
this.m_bmpBackgroundImage = value;
this.Invalidate();
}
}

#if DESIGN
public bool ShouldSerializeBackgroundImage()
{
return (m_bmpBackgroundImage != null);
}
// public override void ResetBackgroundImage()
// {
// BackgroundImage = null;
// }
#endif

However this doesn't seem to work, or atleast I don't get it to work... are
there any special circumstances to think about when it comes to the
BackgroundImage property??

thanks,
Peter



Alex Yakhnin said:
Try to add the follwoing:

#if DESIGN
public bool ShouldSerializeBackColor()
{
return (backColor != Color.Empty);
}
public override void ResetBackColor()
{
BackColor = Color.Empty;
}
#endif

HTH... Alex
--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org

PeterB said:
Hello everyone!

I am creating a custom label that could be used in VS design time. I am
inheriting from Control and do all of my drawing myself. I can add a
label
to a design form in VS, resize it, change colors (back and fore), change
the
font and of course the text. It all looks fine on the VS IDE design form.

The problem is that the code, that reflect the color/font changes, is not
applied to the InitializeComponent method, so if if I close VS and open
it
again, the label is reset to it's original color/font values.

Any help here would be greatly appreciated!

/ Peter


Some more info:
I am overriding ForeColor and BackColor

In my control I use the following members to save the color information:
private Color m_backColor = Color.White; //Color.Empty;
private Color m_foreColor = Color.Black;

I then have 2 overridden properties (1 shown)
/// <summary>
/// Gets or sets the background color for the control.
/// </summary>
#if DESIGN
[
Category("Appearance"),
Description("The background color used to display text in the SIB
control.")
]
#endif
public override Color BackColor
{
get
{
if ((m_backColor == Color.Empty) && (this.Parent != null))
{
return Parent.BackColor;
}
return m_backColor;
}
set
{
m_backColor = value;
this.Invalidate();
}
}
 

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

Top