回复 1楼DCAgile的帖子
测试代码如下:
- [code]
- private void Form1_Load(object sender, EventArgs e)
- {
- TXTextControl.LoadSettings ls = new LoadSettings();
- ls.ApplicationFieldFormat = ApplicationFieldFormat.MSWord;
-
- this.txContent.Load("..\\..\\template1.doc", TXTextControl.StreamType.MSWord);
- //this.txContent.Load("..\\..\\1.tx", TXTextControl.StreamType.InternalUnicodeFormat);
- TXTextControl.DocumentTargetCollection DTC = this.txContent.DocumentTargets;
- List<int> bookmarks = new List<int>();
- foreach (DocumentTarget item in DTC)
- {
- bookmarks.Add(item.Start);
- }
- this.txContent.Select(bookmarks[0], bookmarks[1] - bookmarks[0]);
- TextField tf = new TextField();
- tf.Text = this.txContent.Selection.Text;
- tf.Name = this.txContent.Selection.Text;
- tf.ID = 55;
- this.txContent.Selection.Text = "";
- this.txContent.Select(bookmarks[0], 0);
- this.txContent.TextFields.Add(tf);
- this.txContent.TextFieldClicked += new TextFieldEventHandler(txContent_TextFieldClicked);
- this.txContent.Select(bookmarks[0], bookmarks[1] - bookmarks[0]);
- this.txContent.Selection.TextBackColor = Color.Red;
- }
- void txContent_TextFieldClicked(object sender, TextFieldEventArgs e)
- {
- MessageBox.Show(e.TextField.Name);
- MessageBox.Show(e.TextField.ID.ToString());
- }
复制代码
[/code] |