C1PrintDocument提供了可供报表用户交互的接口,如您可获得RenderObject进行字符输入内容判断、只读属性设置、修改控件显示名称等。
在本例中,我们依次实现如下三点交互性. 更多的内容,请参阅产品demo—C1Report-Acroform 。
- 字符输入内容判断:
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); } } }
- 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); }
- 源码下载: