There are a couple ways to do this. Let's assume, for example, that you
wanted to have a default value of Microsoft Sans Serif, 12 pt, Bold. Then
you could do something like this.
private Font _font = new Font("Microsoft Sans Serif", 12.0F,
FontStyle.Bold);
[DefaultValue(typeof(Font), "Microsoft Sans Serif, 12pt, style=Bold")]
public override Font Font
{
get
{
return _font;
}
set
{
_font = value;
}
}
If you could not get the DefaultValue attribute to work in some situation,
then you could always use the ShouldSerializeXXX and ResetXXX methods.
http://msdn.microsoft.com/library/de...setmethods.asp
--
Tim Wilson
..NET Compact Framework MVP
"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...
Hi Tim,
I could do that, but how would I then set a default Font value? The
DefaultValue attribute seems to only want to accept static values.
Thanks,
Mike
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:uI**************@TK2MSFTNGP11.phx.gbl... AFAIK, you can't. You'll need to override the entire Font property and
pick
up the other values from base.Font.
--
Tim Wilson
.NET Compact Framework MVP
"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:u9**************@TK2MSFTNGP11.phx.gbl... How can you subclass a control and override just a sub-property like
Font.Size?
I was trying to do something like this:
namespace Compeat.Common.Controls
{
public class MyTextBox : TextBox
{
public MyTextBox()
{
this.Font.Size = 12;
}
[DefaultValue(12)]
public override float Font.Size
{
get { return base.Font.Size; }
set { base.Font.Size = value; }
}
}
}
TIA,
Mike Rodriguez