Change column font style runtime in crystal report

2019-09-15 04:20发布

问题:

I have Crystal reports in my project that is designed using a data set (Having table with column name inLanguage1, inLanguage2).

This data set is filled with data from one of the tables from a database, each table have two columns that store names in two different languages.

Eg: Table 1 has name in Hindi and English. Table 2 has name in English and Hindi. Table 3 has name in Kannada and Hindi.

While I store names in these tables, using my frontend (C#), I have set the corresponding font type for the textbox to type the name in that language. (For Hindi, I have set the textbox font as 'Devnagri' which I have installed on my system and so will display in textbox property explorer. For English, font-type is Arial). This data is being stored in corresponding table.

Now, when I fetch table data at run time and fill the data sets it works fine. But, I also want to set the font for the column in the report I am going to print.

Eg: For table1, in Crystal reports I want to set 'Devnagri' as first column's font, second column's font as 'Arial' and, if dataset is filled with data from table2, I want to set font property of report's first column to 'Arial' and second column to 'Devnagri'

So, please suggest a way to do this font setting for Crystal reports in C#.

回答1:

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 TextObject.

TextObject MyText = (TextObject)Repotrdocumentobject.ReportDefinition.ReportObjects[i];

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

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



回答2:

There is a link here. which shows how to change the font of a FieldObject.

For example:

FieldObject field;
field = Report.ReportDefinition.ReportObjects[reportObjectName] as FieldObject;
field.ApplyFont(YourFont);

Since the name of the font is stored in the table, you should be able to make a font from the FontFamily you have stored there.

I assume that you are using standard TextObjects to display values, so in this case, this should work for you.