Microsoft KB Archive/277712

= How To Change the Axis Label Font and the Font Size in MSChart =

Article ID: 277712

Article Last Modified on 6/29/2004

-

APPLIES TO


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

-



This article was previously published under Q277712



SUMMARY
When you work with the MSChart control, you can change the font or font size programmatically with the Labels collection of each axis.



MORE INFORMATION
The following code changes the font and font size for both axes of an MSChart object.

Step-by-Step Example
 Open a new Standard EXE project in Visual Basic 6.0. Form1 is created by default. On the Project menu, select Components to bring up the Components dialog box. Check Microsoft Chart Control, and then click OK. Add a CommandButton control and an MSChart control to Form1.  Add the following code to the code window of Form1 Private Sub Command1_Click ' Note that MSChart20Lib is for Visual Basic 6.0 ' it should be MSChartLib in Visual Basic 5.0 Dim currentaxis As MSChart20Lib.Axis Dim currentlabel As MSChart20Lib.Label ' Get a reference to the x axis Set currentaxis = MSChart1.Plot.Axis(VtChAxisIdX) ' Loop though and set the font of each label For Each currentlabel In currentaxis.Labels currentlabel.VtFont.Name = &quot;Courier&quot; currentlabel.VtFont.Size = 16 Next currentlabel ' get a reference to the y axis Set currentaxis = MSChart1.Plot.Axis(VtChAxisIdY) ' loop through and set the font of each label For Each currentlabel In currentaxis.Labels currentlabel.VtFont.Name = &quot;Courier&quot; currentlabel.VtFont.Size = 16 Next currentlabel End Sub  Run the project, and note the font for the axis labels. Click on Command1, and note that the font changes.</ol>

Keywords: kbhowto kbcodesnippet kbctrl KB277712

-

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

© Microsoft Corporation. All rights reserved.