C1PrintDocument的交互性接口:RenderObject对象

C1PrintDocument提供了可供报表用户交互的接口,如您可获得RenderObject进行字符输入内容判断、只读属性设置、修改控件显示名称等。

发布于 2014/04/18 00:00

ComponentOne Enterprise

C1PrintDocument提供了可供报表用户交互的接口,如您可获得RenderObject进行字符输入内容判断、只读属性设置、修改控件显示名称等。

C1Report

在本例中,我们依次实现如下三点交互性.    更多的内容,请参阅产品demo—C1Report-Acroform

Demo-C1Report

  • 字符输入内容判断:
     doc.InputValueChanged += new InputValueChangedEventHandler(doc_InputValueChanged);
    
            void doc_InputValueChanged(C1PrintDocument sender, InputValueChangedEventArgs e)
            {
                valid = true;
                if (e.RenderObject.GetType() == typeof(RenderInputText))
                {
                    if ((e.RenderObject.Name == rit1.Name) && (e.RenderObject as C1.C1Preview.RenderInputText).Text.Length > 8)
                    {
                        string txt = (e.RenderObject as C1.C1Preview.RenderInputText).Text;
                        MessageBox.Show("Clipping text greater than 8", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        rit1.Text = txt.Substring(0, 8);
                        doc.Generate(RefreshModeEnum.RefreshDataBinding);
                    }
                }
            }
     
    InputValueChanged事件, 类似Winform中的TextBox的ValueChange事件,如输入超过8个字符,则进行截取并MessageBox判断。
  • RenderInputText设置只读属性:
    RenderInputText控件,同Winform中的TextBox控件,默认是读写的。如我们要设置为只读属性,可通过在UI上添加一个Button,触发Click事件,进行只读属性修改,修改完,要重新生成一遍报表Generate(RefreshModeEnum.RefreshDataBinding).

    rit2=RenderInputText。
     private void button2只读_Click(object sender, EventArgs e)
     {
       rit2.ReadOnly = true;
       doc.Generate(RefreshModeEnum.RefreshDataBinding);
     }
  • 修改RenderInputButton的显示文字
    RenderInputButton控件,同Winform中的Button控件。如我们可对其进行设置显示文字进行改值操作,可通过在UI上添加一个Button,触发Click事件,通过FindByName获得RenderInputButton对象进行赋值。

      private void button1你好_Click(object sender, EventArgs e)
      {
          RenderInputButton btn = doc.Body.Children.FindByName("nihaoButton") as RenderInputButton;
          btn.Text = "你好";
          doc.Generate(RefreshModeEnum.RefreshDataBinding);
       }
      源码下载:

ComponentOne Enterprise | 下载试用

ComponentOne 是一套专注于企业 .NET开发、支持 .NET Core 平台,并完美集成于 Visual Studio 的第三方控件集,包含 300 多种 .NET开发控件,提供表格数据管理、数据可视化、报表和文档、日程安排、输入和编辑、导航和布局、系统提升工具等七大功能,被誉为“.NET开发的‘瑞士军刀’”。

ComponentOne 为您提供专业的产品咨询服务,并由技术支持工程师为您1对1解答。>> 发帖提问

相关产品
推荐相关案例
关注微信
葡萄城社区二维码

关注“葡萄城社区”

加微信获取技术资讯

加微信获取技术资讯

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态