2016-07-01 84 views
0

我正在使用Visual Studio 2013和水晶報表13.0.12.1494。在我的項目中,我有一個Crystal Report With數據庫字段(SQL Server作爲數據庫)。我在項目設置中存儲對字體的引用,並且想要根據用戶偏好從項目設置 替換字體,例如,用Arial字體,10PT和用戶建立 水晶報表選擇Times New Roman字體,12磅在運行時則報告應在Times New Roman字體顯示,12磅如何使用vb.net動態更改水晶報表字體

我試過之後沒有成功

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

謝謝Advance

回答

1

這裏是我用來動態改變我的對象的字體的c#。

文本對象可以是TextObject(簡單的文本)或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方法。 你可以解析你的字體,然後使用ApplyFont