使用C1PrintDocument控件 > 表达式,脚本,标签 > 在运行时编辑标签值 > 指定Tags对话框何时显示 |
当ShowTagsInputDialog属性设置为True,则会在文档生成之前显示Tags对话框。您可以通过编程方式调用EditTags方法显示该对话框,(和ShowTagsInputDialog属性的设置是完全独立的)。
例如,下面的代码将会使得单击一个按钮时,显示的标签输入对话框:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Public Class Form1 Dim doc As New C1PrintDocument() Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.C1PrintPreviewControl1.Document = doc ' 创建将用来显示的标签 doc.Tags.Add(New C1.C1Preview.Tag("Statement", "Hello World!")) doc.Tags("Statement").ShowInDialog = True doc.Tags.Add(New C1.C1Preview.Tag("Name", "ComponentOne")) doc.Tags.Add(New C1.C1Preview.Tag("Location", "Pittsburgh, PA")) ' 向文档添加标签 Dim rt As New C1.C1Preview.RenderText() rt.Text = "[Statement] My name is [Name] and my current location is [Location]." doc.Body.Children.Add(rt) End Sub Private Sub EditTagsNow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditTagsNow.Click ' 在单击按钮时显示Tags对话框 doc.ShowTagsInputDialog = True doc.EditTags() End Sub Private Sub GenerateDocNow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerateDocNow.Click doc.ShowTagsInputDialog = False ' 单击按钮时生成文档 doc.Generate() End Sub End Class |
C#
C# |
拷贝代码
|
---|---|
public partial class Form1 : Form { public Form1() { InitializeComponent(); } C1PrintDocument doc = new C1PrintDocument(); private void Form1_Load(object sender, EventArgs e) { this.c1PrintPreviewControl1.Document = doc; // 创建将用来显示的标签 doc.Tags.Add(new C1.C1Preview.Tag("Statement", "Hello World!")); doc.Tags["Statement"].ShowInDialog = true; doc.Tags.Add(new C1.C1Preview.Tag("Name", "ComponentOne")); doc.Tags.Add(new C1.C1Preview.Tag("Location", "Pittsburgh, PA")); // 向文档添加标签 C1.C1Preview.RenderText rt = new C1.C1Preview.RenderText(); rt.Text = "[Statement] My name is [Name] and my current location is [Location]."; doc.Body.Children.Add(rt); } private void EditTagsNow_Click(object sender, EventArgs e) { // 在单击按钮时显示Tags对话框 doc.ShowTagsInputDialog = true; doc.EditTags(); } private void GenerateDoc_Click(object sender, EventArgs e) { doc.ShowTagsInputDialog = false; // 单击按钮时生成文档 doc.Generate(); } } |
在上面的例子中,单击EditTagsNow按钮时,会显示Tags对话框。