DCAgile 发表于 2015-9-18 14:19:00

TX Control如何获取点击的Merge Field 的Name属性

模版内容如附件template1.doc   (代码中存在公司的数据库文件,不方便直接发送)

注意:收到日期: «ReceiveDate»   添加有bookmark标记

通过如下代码添加事件:
//第一个TextField            
            this.txContent.Select(bookmarks, bookmarks - bookmarks);
            TextField tf = new TextField();
            tf.Text = this.txContent.Selection.Text;
            this.txContent.Selection.Text = "";
            this.txContent.Select(bookmarks, 0);
            this.txContent.TextFields.Add(tf);


1.单击后需要获取 当前单击项的Name属性 (ReceiveDate),,,如何获取??

2.能否将如上所示的TextField 转换为: TXTextControl.ApplicationField appField = (TXTextControl.ApplicationField)e.TextField;??

3.如何通过代码的方式在模版中动态加载图片(图片个数不定,每张加载图片需要有间隔)?

iceman 发表于 2015-9-18 17:04:00

回复 1楼DCAgile的帖子

出先问题的原因是,模板中添加的是 mergefield,而在执行了 1# 代码后替代为 TextField,而没有设置 TextField 的name属性。所以拿不到。

我查看了模板,直接把 Selection.Text 设置给 TextField.Name 属性。

iceman 发表于 2015-9-18 17:42:00

回复 1楼DCAgile的帖子

测试代码如下:



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, bookmarks - bookmarks);
            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);

            this.txContent.TextFields.Add(tf);

            this.txContent.TextFieldClicked += new TextFieldEventHandler(txContent_TextFieldClicked);
            this.txContent.Select(bookmarks, bookmarks - bookmarks);
            this.txContent.Selection.TextBackColor = Color.Red;
      }

      void txContent_TextFieldClicked(object sender, TextFieldEventArgs e)
      {
            MessageBox.Show(e.TextField.Name);
            MessageBox.Show(e.TextField.ID.ToString());
      }

DCAgile 发表于 2015-9-18 18:03:00

回复 3楼iceman的帖子

1.通过如下代码添加TextField
TextField tf = new TextField();
            tf.Text = this.txContent.Selection.Text;
            tf.Name = this.txContent.Selection.Text;
            tf.ID = 55;
            this.txContent.Selection.Text = &quot;&quot;;
            this.txContent.Select(bookmarks, 0);

            this.txContent.TextFields.Add(tf);
通过:TXTextControl.ApplicationField appField = (TXTextControl.ApplicationField)e.TextField;   转换失败,

问题:1.是否可以通过TXTextControl.ApplicationField appField = (TXTextControl.ApplicationField)e.TextField;进行转换?

2.如何通过代码的方式在模版中动态加载图片(图片个数不定,每张加载图片需要有间隔)?

iceman 发表于 2015-9-21 10:33:00

回复 4楼DCAgile的帖子

TextField 和 ApplicationField 是两个处于不同命名空间下的没有关联的两个类,无法进行转换。可以在 4# 代码中直接使用 ApplicationField 替代mergefield。这样就减少了一次转换。

动态加载图片请参考:http://blog.gcpowertools.com.cn/post/2013/11/12/TX_Text_Control_Image_AutoSize.aspx

DCAgile 发表于 2015-9-21 11:30:00

TX 通过事件添加控件

回复 5楼iceman的帖子

1.事件已经添加成功,但通过如下代码:
if (id == 1)
            {
                DateField df = Helper.Instance.AddDateField(this.txContent);
                AddDateTimePicker(point);
            }
添加的控件未能正常显示,请查看是什么问题???

iceman 发表于 2015-9-21 14:00:00

回复 6楼DCAgile的帖子

问题已经查收,调查后给你反馈。

DCAgile 发表于 2015-9-21 16:53:00

回复 7楼iceman的帖子

问题1.在 private void AddControlByPoint(Point point, int id){...}中添加的AddDateTimePicker(point);无法显示,(请协助查看问题原因)

2.通过电话沟通中,经您反映更改添加TextField 方式为ApplicationField方式,如何处理(可直接在提供的实例中进行更改)??

麻烦尽快处理,我们这边领导对这个任务跟进的比较急

iceman 发表于 2015-9-21 19:13:00

回复 8楼DCAgile的帖子

你好,代码逻辑比较复杂,当前我无法读懂,明天和你电话沟通情况。

iceman 发表于 2015-9-22 10:25:00

回复 8楼DCAgile的帖子

已完成,请查看:
页: [1] 2
查看完整版本: TX Control如何获取点击的Merge Field 的Name属性