C1PrintDocument的交互性接口:RenderObject对象

发布时间:2014/04/18 00:04 发布者:roger.wang

返回博客中心

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);
       }
      源码下载:

关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网