Changing font at runtime


03-04-2010, 6:56 PM
I am customizing one of my reports and a font installed in my system is not available to use for my text objects.

Are their methods for programmatically setting the font from the script side?

I have seen posts about creating a font at runtime to adjust font attributes...

Re: Changing font at runtime


03-04-2010, 7:39 PM
One option is use the themes feature to modify major and minor fonts in your report. You can modify the theme file (XML) once and it will be picked up by all reports using it.

Re: Changing font at runtime


03-05-2010, 2:22 PM
so to be more clear, I am writing custom reports inside of an application called D-Tools which utilizes ActiveReports as its reporting engine. I'm not sure where to find the theme XML file (if my application actually uses it).

Re: Changing font at runtime


03-08-2010, 6:39 AM
fryeguy,
You can use the font property of the control to set its Font attribute at runtime. Take a look at this link.
Let me know if you need more assistance.

Regards,
Aashish

Re: Changing font at runtime


03-08-2010, 8:06 AM
I am sorry, you posted your question in the DDR forum and did not indicate that you were using ActiveReports and not DDR. Themes is a feature of DDR not AR. Please see Aashish's reply.

Re: Changing font at runtime


03-09-2010, 3:45 PM
I checked out the link and it makes perfect sense to me. However I am not having much luck implementing this code.

Maybe a couple of questions will guide us in how I should proceed:

1. Is there any specific criteria that might make a font installed on my system not available to the report designer? OpenType, TrueType?

2. When I am creating the new font using the font property, does this have to been done for every Label and Textbox I want to apply the font to? Based on the code it looks like this is the case.

3. I haven't done a great deal of VB.NET but some older VB. In the context of the report script does the "Me" in Me.Label1... refer to the report, the report section, or something else?

4. I get a couple of errors:

a) Handles clause requires a WithEvents variable defined in the containing type or one of its base types...
I looked at some different causes for this error but I can't quite figure out how to resolve it. I know the report designer is using VB.NET for scripting.

b) 'Label1' is not a member of 'DataDynamics.ActiveReports.ActiveReport3'.
This error is regarding my hacked together code: rpt.Label1.Font = New System.Drawing.Font = ("MinionPro"),
where Label1 is the name of a Label I want to apply the font to.

Re: Changing font at runtime


03-09-2010, 4:32 PM
1. There should be nothing we are doing to filter out available fonts. It may be a case of a user not having permissions for some fonts. A quick way to test this would be to right click your application and run it as Administrator.


2. You can use scripting to modify the default style class of the report controls which is "Normal":

Sub Detail1_Format
    rpt.StyleSheet("Normal").FontName = "Times New Roman"   
End Sub


3. Scripting in ActiveReports for .NET 3.0 does not have access to the members of the report class. So controls would need to be accessed by indexes or names:

CType(rpt.Sections("Detail1").Controls("Label1"), Label).Font = new Font("Arial", 10)


4. Errors:

a) When using scripting (not code-behind), the Handles clause should not appear after the event handler declaration as it would in VB.NET code. Scripting follows the same syntax as VB.NET generally speaking, but there are some differences.

b) Answer is above for question 3.


Let me know if you have any more questions.


-Jon

Re: Changing font at runtime


03-09-2010, 6:08 PM
Using this code:

CType(rpt.Sections("grpHeadings").Controls("Label1"), Label).Font = new Font ("Minion Pro", 10)

I can actually preview and publish the report.

I can tell the code has an effect because while the font is still Arial or something close, the code wipes out the formatting set by the report designer control.

What is it with this font that is so strange?

FYI, I am always running as an adminstrator of my local machine...

Re: Changing font at runtime


03-10-2010, 9:54 PM
Hello,

Did you reboot the machine after you installed the font? Could you provide me the fonts so that I can try to reproduce the issue at my end? Make sure that the font should be of TrueType as ActiveReports uses GDI+ rendering, which only support TrueType fonts.

Regards,
Ankit Nigam

Re: Changing font at runtime


03-11-2010, 11:50 AM
Turns out this was definitely an OpenType font. I found a font conversion website: http://www.fontconverter.org/

The site is self-explanatory. convert font, reinstall the new converted font and ActiveReports will play nice.