找回密码
 立即注册

QQ登录

只需一步,快速开始

DCAgile

中级会员

83

主题

247

帖子

794

积分

中级会员

积分
794

活字格认证微信认证勋章元老葡萄

DCAgile
中级会员   /  发表于:2015-9-18 14:19  /   查看:9109  /  回复:10
模版内容如附件template1.doc   (代码中存在公司的数据库文件,不方便直接发送)

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

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


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

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

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

template1.doc

14 KB, 下载次数: 109

10 个回复

倒序浏览
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的帖子

测试代码如下:


  1. [code]
  2. private void Form1_Load(object sender, EventArgs e)
  3.         {
  4.             TXTextControl.LoadSettings ls = new LoadSettings();
  5.             ls.ApplicationFieldFormat = ApplicationFieldFormat.MSWord;
  6.             
  7.             this.txContent.Load("..\\..\\template1.doc", TXTextControl.StreamType.MSWord);
  8.             //this.txContent.Load("..\\..\\1.tx", TXTextControl.StreamType.InternalUnicodeFormat);


  9.             TXTextControl.DocumentTargetCollection DTC = this.txContent.DocumentTargets;
  10.             List<int> bookmarks = new List<int>();


  11.             foreach (DocumentTarget item in DTC)
  12.             {
  13.                 bookmarks.Add(item.Start);
  14.             }

  15.             this.txContent.Select(bookmarks[0], bookmarks[1] - bookmarks[0]);
  16.             TextField tf = new TextField();
  17.             tf.Text = this.txContent.Selection.Text;
  18.             tf.Name = this.txContent.Selection.Text;
  19.             tf.ID = 55;
  20.             this.txContent.Selection.Text = "";
  21.             this.txContent.Select(bookmarks[0], 0);

  22.             this.txContent.TextFields.Add(tf);

  23.             this.txContent.TextFieldClicked += new TextFieldEventHandler(txContent_TextFieldClicked);
  24.             this.txContent.Select(bookmarks[0], bookmarks[1] - bookmarks[0]);
  25.             this.txContent.Selection.TextBackColor = Color.Red;
  26.         }

  27.         void txContent_TextFieldClicked(object sender, TextFieldEventArgs e)
  28.         {
  29.             MessageBox.Show(e.TextField.Name);
  30.             MessageBox.Show(e.TextField.ID.ToString());
  31.         }
复制代码

[/code]
回复 使用道具 举报
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], 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
5#
回复 4楼DCAgile的帖子

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

动态加载图片请参考:http://blog.gcpowertools.com.cn/ ... Image_AutoSize.aspx
回复 使用道具 举报
DCAgile
中级会员   /  发表于:2015-9-21 11:30:00
6#

TX 通过事件添加控件

回复 5楼iceman的帖子

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

DBAndTemplate.rar

209.97 KB, 下载次数: 87

回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-9-21 14:00:00
7#
回复 6楼DCAgile的帖子

问题已经查收,调查后给你反馈。
回复 使用道具 举报
DCAgile
中级会员   /  发表于:2015-9-21 16:53:00
8#
回复 7楼iceman的帖子

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

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

麻烦尽快处理,我们这边领导对这个任务跟进的比较急
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-9-21 19:13:00
9#
回复 8楼DCAgile的帖子

你好,代码逻辑比较复杂,当前我无法读懂,明天和你电话沟通情况。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-9-22 10:25:00
10#
回复 8楼DCAgile的帖子

已完成,请查看:
BookMark.zip (81.95 KB, 下载次数: 73)
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部