user1418842
user1418842

Reputation: 41

set fontstyle of a column of a crystal report programatically?

how to -change (set ) font for a column of a crystal report programatically (dont want to use 'Format editor' at design time)? whats the syntax used to access the field (column ) of detail section of the crystal report ..?

thanks in advance .

Upvotes: 2

Views: 6790

Answers (3)

Salim Latif Waigaonkar
Salim Latif Waigaonkar

Reputation: 462

Changing Font style,Font Size,and Font at runtime in Crystal Report use following code,this will run properly:

you can use TextObject or FieldObject Depending on your condition.here am using FieldObject.

 FieldObject MyText (FieldObject)Repotrdocumentobject.ReportDefinition.ReportObjects[i];

MyText.ApplyFont(new Font("Arial", 11f,FontStyle.Bold));

here i is number of FieldObject in Crystal Report and 11f is font size

Upvotes: 3

Hamidreza
Hamidreza

Reputation: 3118

you can add CRAXDRT to your references and then use it like this

        CRAXDRT.Report report1 = new CRAXDRT.Report();
        CRAXDRT.Application app1 = new CRAXDRT.Application();


        stdole.IFontDisp myFont;
        report1 = app1.OpenReport("Test.rpt", OpenReportMethod.OpenReportByDefault);

        foreach (CRAXDRT.Section sec in report1.Sections)
        {
            for (int i = 1; i < sec.ReportObjects.Count + 1; i++)
            {
                 object objMain, objChange;
                objMain = report1.Sections[sec.Name].ReportObjects[i];

                try
                {
                    objChange = objMain;
                    CRAXDRT.TextObject to1 = (CRAXDRT.TextObject)objChange;
                    myFont = to1.Font;
                    myFont.Name = "Arial";
                    to1.Font = myFont;

                }
                catch (Exception)
                {
                    try
                    {
                        objChange = objMain;
                        CRAXDRT.FieldObject to1 = (CRAXDRT.FieldObject)objChange;
                        myFont = to1.Font;
                        myFont.Name = "Arial";
                        to1.Font = myFont;
                    }
                    catch (Exception){}
                }
            }

        }

Upvotes: 0

Lee Tickett
Lee Tickett

Reputation: 6027

Hopefully this code snippet i just threw together will help:

        ReportDocument rpt = new ReportDocument();
        rpt.Load(@"C:\LT0001_COBDEN.rpt");
        foreach (Area a in rpt.ReportDefinition.Areas)
        {
            string s = a.Name;
        }
        foreach (Section c in rpt.ReportDefinition.Sections)
        {
            string s = c.Name;
        }

        ObjectFormat of = rpt.ReportDefinition.Sections["GroupHeaderSection9"].ReportObjects["Text21"].ObjectFormat;
        TextObject to = (TextObject)rpt.ReportDefinition.Sections["GroupHeaderSection9"].ReportObjects["Text21"];
        to.Color = Color.Red;

        crystalReportViewer1.ReportSource = rpt;
        crystalReportViewer1.Refresh();

Upvotes: 0

Related Questions