You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FastReport .NET预览时如何调用Invalidate实现元素重渲染?

FastReport预览界面文本修改即时生效方案

问题描述

使用FastReport Community版本,通过脚本修改预览界面中Text2文本对象的字体大小后,修改效果不会即时显现,只有滚动预览窗口或调整窗口大小后才会显示变化。

原代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using FastReport;
using FastReport.Data;
using FastReport.Dialog;
using FastReport.Barcode;
using FastReport.Table;
using FastReport.Utils;

namespace FastReport
{
  public class ReportScript
  {
      private void Text2_Click(object sender, EventArgs e)
      {
        var obj = sender as TextObject;
        if (obj != null)
        {
          // 修改TextObject的字体大小
          obj.Font = new Font(obj.Font.FontFamily, 15);
        }
      }
   }
}

解决方案

修改点击事件脚本,在完成字体属性修改后,调用预览界面的刷新方法强制重渲染,即可让修改即时生效。

修改后的代码:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using FastReport;
using FastReport.Data;
using FastReport.Dialog;
using FastReport.Barcode;
using FastReport.Table;
using FastReport.Utils;

namespace FastReport
{
  public class ReportScript
  {
      private void Text2_Click(object sender, EventArgs e)
      {
        var obj = sender as TextObject;
        if (obj != null)
        {
          // 修改TextObject的字体大小
          obj.Font = new Font(obj.Font.FontFamily, 15);
          // 强制刷新预览界面,即时显示修改效果
          obj.Report.Preview.Refresh();
        }
      }
   }
}

原理说明

FastReport预览控件默认不会自动监测对象属性的修改并触发即时重绘,手动调用Preview.Refresh()会直接触发整个预览区域的重渲染流程,让字体大小的变化立即显示在界面上,无需等待滚动或窗口调整操作。

内容的提问来源于stack exchange,提问作者Makstvell

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 22:12:44