Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / May 2005

Tip: Looking for answers? Try searching our database.

Font property default value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nick WAELTI - 07 May 2005 13:32 GMT
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,
Nick
Mick Doherty - 07 May 2005 14:30 GMT
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

Signature

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

> Hi,
>
[quoted text clipped - 5 lines]
> Thanks,
> Nick
Nick WAELTI - 09 May 2005 09:24 GMT
Thanks :)

> Private m_Font As Font = New Font("arial", 8.0!, FontStyle.Regular, _
>             GraphicsUnit.Point)
[quoted text clipped - 18 lines]
>             GraphicsUnit.Point)
> End Sub
Tim Wilson - 07 May 2005 14:46 GMT
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);
}

Signature

Tim Wilson
.Net Compact Framework MVP

> Hi,
>
[quoted text clipped - 5 lines]
> Thanks,
> Nick
Nick WAELTI - 09 May 2005 09:24 GMT
Thanks ;)

> In C#, I would do something like this.
>
[quoted text clipped - 27 lines]
>   return (font != null);
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.