Click here to Skip to main content
13,556,900 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


10 bookmarked
Posted 24 Oct 2011
Licenced CPOL

Change Font & Size of Crystal Report Dynamically

, 2 Nov 2011
Rate this:
Please Sign up or sign in to vote.
Change font & size of Crystal report dynamically


This article describes how to change font and size of crystal report dynamically (runtime) in VB.NET 2005.

Using the Code

Open a new Windows application project using VB.NET and add a button, CrystalReportViewer from the Toolbox. Adding the control and dropping it on the form design it as shown in fig.

then add a SQL Database name as “Database1.mdf” create a table name as “Fonts” with 3 fields : FontName, Size, SrNo and set SrNo field value as 1

Imports System.Data.SqlClient

Public Class Form1

    Dim rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    'path variable use for Get application running path
    Dim path As String = (Microsoft.VisualBasic.Left(Application.StartupPath, Len(Application.StartupPath) - 9))
    'connetiong string
    Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" & path & "Database1.mdf;Integrated Security=True;User Instance=True")
    Dim cmd As SqlCommand

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Update query is fired 
        cmd = New SqlCommand("UPDATE Fonts SET FontName ='" & FontDialog1.Font.Name.ToString & "',Size = " & FontDialog1.Font.Size.ToString & " WHERE SrNo = 1", con)
        'Function report call
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Function report call
    End Sub
    Sub report()
        On Error Resume Next
        Dim dset As New DataSet
        Dim adp As New SqlDataAdapter("Select * from Fonts", con)
        adp.Fill(dset, "Fonts")
        'path variable store a runnig application path"
        rpt.Load(path & "CrystalReport1.rpt")
        CrystalReportViewer1.ReportSource = rpt
    End Sub

End Class

Create a crystal report and add field from Database FontName & Size then Add Formula Fields name as “font”.Edit the Formula Field and use html font tag set it attributes face & size save it

The HTML tag is used in crystal report to set a font

Drop the formula field on crystal report then right click on it: Format Object -> Paragraph -> text interpretation -> HTML text -> OK button.


Some font are not supporting to Html tag ,font size will be set 1 to 7 only. This is a drawback.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Patil Kishor
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180515.1 | Last Updated 3 Nov 2011
Article Copyright 2011 by Patil Kishor
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid