2005 Custom Control

  • Thread starter Thread starter Chris Oswald
  • Start date Start date
C

Chris Oswald

Forgive me if this has already been answered. I have created a custom
control which inherits from Windows.Forms.Control. I want set a
default Font for the Font property when the control is originally
created in the designer. I set the default font in the constructor.
Except the designer ignores my information and draws the control with
the it's own font of "Tahoma", 9F, Regular. WTF! If I create some
dummy property called ButtonFont the font works just fine in the
designer. What is the deal?


Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
Me.Font = New Font("Tahoma", 15.0F, FontStyle.Bold)
End Sub

Private _font As Font
Public Overrides Property Font() As Font
Get
Return _font
End Get
Set(ByVal value As Font)
_font = value
Me.Invalidate()
End Set
End Property
 
You are the man. I saw that article referenced somewhere else and
didn't read far enough.

The key is :

<ApplyDeviceDefaults>
<PropertyName>Font</PropertyName>
<ApplyDefaults>false</ApplyDefaults>
</ApplyDeviceDefaults>

Thank you Tim!
 
Back
Top