我有一个包含多个文本框的表单,需要获取这些文本框的值并通过itextsharp将它们插入PDF中。 目前我像这样对每个语句使用 if 语句,
If CheckBox1.Checked Then
pdfFormFields.SetField("CheckBox1", "Yes")
Else
pdfFormFields.SetField("CheckBox1", "No")
End If
我希望对表单中的所有复选框做同样的事情,但希望功能来做到这一点,我已经尝试了几种方法,但似乎找不到一种有效的方法。
我可以使用
foreach(Control c in this.Controls)
{
if(c is CheckBox)
{
// Do stuff here ;]
}
}
遍历它们,但这是检查状态并执行 IM 卡住的操作
假设表单和PDF中的复选框名称相同,您不能这样做:
foreach(var checkbox in this.Controls.OfType<CheckBox>())
{
pdfFormFields.SetField(checkbox.Name, checkbox.Checked ? "Yes": "No");
}