Groups | Blog | Home
all groups > dotnet windows forms designtime > may 2005 >

dotnet windows forms designtime : Font property default value


Nick WAELTI
5/7/2005 12:00:00 AM
Hi,

Does anyone knows how to set a default for a font property ?

I want my property to have the default (not bold) on Arial 8.0! Regular.
How can I achieve that ?

Thanks,
Mick Doherty
5/7/2005 12:00:00 AM
Private m_Font As Font = New Font("arial", 8.0!, FontStyle.Regular, _
GraphicsUnit.Point)

Public Property [Font]() As Font
Get
Return m_Font
End Get
Set(ByVal Value As Font)
m_Font = Value
End Set
End Property

Private Function ShouldSerializeFont() As Boolean
Return Not (m_Font.SizeInPoints = 8.0! AndAlso _
m_Font.Style = FontStyle.Regular AndAlso _
m_Font.Name.ToLower = "arial")
End Function

Private Sub ResetFont()
m_Font = New Font("arial", 8.0!, FontStyle.Regular, _
GraphicsUnit.Point)
End Sub

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


[quoted text, click to view]

Tim Wilson
5/7/2005 9:46:04 AM
In C#, I would do something like this.

private static readonly Font DefaultFontValue = new Font("Arial", 8.0F,
FontStyle.Regular);
private Font font = null;

[AmbientValueAttribute(null)]
public override Font Font
{
get
{
if (font == null)
{
return DefaultFontValue;
}
return font;
}
set
{
if (font != value)
{
font = value;
this.Invalidate();
}
}
}

protected virtual bool ShouldSerializeFont()
{
return (font != null);
}

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

Nick WAELTI
5/9/2005 12:00:00 AM
Thanks :)

[quoted text, click to view]
Nick WAELTI
5/9/2005 12:00:00 AM
Thanks ;)

[quoted text, click to view]
AddThis Social Bookmark Button