如何使用vb.net动态更改Crystal Report字体

时间:2016-07-01 07:23:21

标签: vb.net crystal-reports crystal-reports-2008

我正在使用带有水晶报告13.0.12.1494的Visual Studio 2013。在我的项目中,我有一个Crystal Report With Database from fields(SQL Server as Database)。我在项目设置中存储对字体的引用,并希望根据项目设置中的用户首选项替换字体 例如水晶报告用字体arial,10pt和用户选择时间新罗马,12pt在运行时然后报告应该显示新罗马,12pt。

我尝试过没有成功

Dim myparam As New ParameterField
Dim myDiscreteValue As New ParameterDiscreteValue
myparam.ParameterFieldName = "My Parameter"
myDiscreteValue.Value = My.Settings.MyFont.Name

先谢谢

2 个答案:

答案 0 :(得分:2)

以下是用于动态更改对象字体的c#。

文本对象可以是YourContext.CreateQuery<bool>( "SELECT VALUE YourModel.Store.UserDefinedFunction(@Parameter1) FROM {1}", new ObjectParameter("Parameter1", Parameter1Value)).First(); (简单文本)或TextObject(来自db)

FieldObject

这两个类都有 public static void ApplyFontAllText(ReportDocument rapport, Font style) { foreach (ReportObject obj in rapport.ReportDefinition.ReportObjects) { if (obj.GetType().Name.Equals("TextObject")) { ((TextObject)obj).ApplyFont(style); } else if (obj.GetType().Name.Equals("FieldObject")) { ((FieldObject)obj).ApplyFont(style); } } } 方法。 您可以解析字体,然后使用ApplyFont

答案 1 :(得分:0)

VB版:

Dim templatefont As Font

'scan all report objects in the crystal report _reportDoc
For Each x As ReportObject In _reportDoc.ReportDefinition.ReportObjects
  'just change the font family. Keep styling (e.g. bold) same
  If x.GetType.Name.Equals("TextObject") Then
     templatefont = DirectCast(x, TextObject).Font
     DirectCast(x, TextObject).ApplyFont(New Font("Arial Unicode MS", templatefont.Size, templatefont.Style, templatefont.Unit))
  End If

  If x.GetType.Name.Equals("FieldObject") Then
     templatefont = DirectCast(x, FieldObject).Font
     DirectCast(x, FieldObject).ApplyFont(New Font("Arial Unicode MS", templatefont.Size, templatefont.Style, templatefont.Unit))         
  End If
Next
相关问题