我按照您说的方法做了一下,还是不行啊,会抛异常
我就是添加了一个按钮的点击事件,代码如下C:\Users\Administrator\Desktop\异常.png
private void testforprintbtn_Click(object sender, EventArgs e)
{
int length = this.textControl1.TextFields.GetItem(0).Length;
TXTextControl.TextField testfields = new TextField();
//foreach (TXTextControl.TextField tf in this.textControl1.TextFields)
//{
// testfields.Text += tf.Text;
//}
int selectlength = 1;
for (int i = 0; i < length; i++)
{
this.textControl1.Selection.Start = i;
this.textControl1.Selection.Length = selectlength;
if (this.textControl1.Selection.ForeColor.Name.ToString() == "ff000000")//只要文本中黑色字体的文字
{
testfields.Text += this.textControl1.Selection.Text;
}
}
viewform viform = new viewform(testfields);//新建一个textcontrol窗口来显示获得的文本
viform.ShowDialog();
} |