Microsoft KB Archive/208654

= BUG: FontChanged Event Fires Twice When a Property of a Font Object is Changed =

Article ID: 208654

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q208654



SYMPTOMS
The FontChanged event sink fires more than once if the user sets a Stdfont object to a font more than once. Setting the font object twice may be necessary if the font object is destroyed for some reason, and then recreated. The expected behavior is that the FontChanged event fires only once when a property is changed.



RESOLUTION
Create the font object explicitly again after destroying it, and then set up the properties again. This makes the event fire only once.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Start a new Standard EXE project in Visual Basic. Form1 is created by default. Add a CommandButton control to Form1.  Add the following code to Form1's code module: Option Explicit Private WithEvents f As StdFont

Private Sub Command1_Click Me.Font.Bold = Not Me.Font.Bold End Sub

Private Sub f_FontChanged(ByVal PropertyName As String) Print PropertyName End Sub

Private Sub Form_Load Set f = Me.Font Set f = Me.Font End Sub  Press the F5 key to run the project, and then click the CommandButton. The Bold property is being changed. Note that the word Bold is printed twice on the form.</ol>

Step-by-Step Resolution
<ol> Start a new Standard EXE in Visual Basic. Form1 is created by default.</li> Add a CommandButton control to Form1.</li>  Add the following code to the code module of Form1: Option Explicit Private WithEvents f As StdFont Private x As StdFont

Private Sub Command1_Click Me.Font.Bold = Not Me.Font.Bold End Sub

Private Sub f_FontChanged(ByVal PropertyName As String) Print PropertyName End Sub

Private Sub Form_Load Set x = New StdFont x.Name = "Times New Roman" x.Bold = True x.Italic = True Set f = x  Set Me.Font = f

Set x = New StdFont x.Name = "Times New Roman" x.Bold = True x.Italic = False Set f = x  Set Me.Font = f End Sub </li> Press the F5 key to run the project, click the CommandButton, and note that the word Bold is printed only once.</li></ol>

Keywords: kbbug kbfont kbpending KB208654

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.