找回密码
 立即注册

QQ登录

只需一步,快速开始

mindrayguowei

中级会员

122

主题

274

帖子

986

积分

中级会员

积分
986

活字格认证

QQ
mindrayguowei
中级会员   /  发表于:2015-10-28 15:19  /   查看:9421  /  回复:10
通过程序向TextControl中插入图片,有些图片可能有相应的图片描述, 图片和文字都来自于数据库。
现在插入图片是根据配置好的图片坐标插入到控件的相应位置,现在要插入文字,要求显示在图片下方。

现在的做法是插入一个TextField到控件,插入的时候设置InputPosition,这个也可以从配置读取。现在的问题是这个配置无效,无论横坐标设置多大,始终显示在最左边。
我的测试代码如下:


  1. TextField textField = new TextField("赵志敬");
  2. _textControl.InputPosition = new InputPosition(new System.Drawing.Point(config.Left, config.Top + (int)config.Height));
  3. _textControl.TextFields.Add(textField);
复制代码


请问要怎么插入到配置的坐标下,或者是否可以别的方案实现这个需求?

10 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2015-10-28 16:56:00
沙发
回复 1楼mindrayguowei的帖子

TX 文字是基于文本流的,例如:文本只有 1 个字符,我们就无法插入 textfiled 到第10个字符的位置。

所以,您的这个case需要通过插入Table或者空格占位。
回复 使用道具 举报
mindrayguowei
中级会员   /  发表于:2015-10-28 17:47:00
板凳
能给出demo代码吗?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-10-29 10:35:00
地板
回复 3楼mindrayguowei的帖子

这个demo制作起来可能比较复杂,不知道现在您能否提供些现在的实现代码,例如插入图片和计算文字插入位置的代码。我们在这基础上协助调查。
回复 使用道具 举报
mindrayguowei
中级会员   /  发表于:2015-10-29 13:35:00
5#
  1. for (int i = 0; i < _imagePathList.Count; i++)
  2.         {
  3.             string fileName = _imagePathList[i];
  4.             ReportImageConfig config = reportImageConfigList[i];
  5.             Image image = new Image(fileName, 5);
  6.             image.SaveMode = ImageSaveMode.SaveAsData;
  7.             System.Drawing.Image img = System.Drawing.Image.FromFile(fileName);
  8.             int vScaleFactor = Convert.ToInt32(config.Height / (img.Height * TwipsPerPixel) * 100);
  9.             int hScaleFactor = Convert.ToInt32(config.Width / (img.Width * TwipsPerPixel) * 100);
  10.             img.Dispose();
  11.             img = null;
  12.             image.HorizontalScaling = hScaleFactor;
  13.             image.VerticalScaling = vScaleFactor;
  14.             _textControl.Images.Add(image, config.Location, ImageInsertionMode.DisplaceCompleteLines);
  15.             //TextField textField = new TextField("赵志敬");
  16.             //_textControl.InputPosition = new InputPosition(new System.Drawing.Point(config.Left, config.Top + (int)config.Height));
  17.             //_textControl.TextFields.Add(textField);
  18.         }
  19.         class ReportImageConfig
  20.         {
  21.             private string _field = string.Empty;
  22.             private int _id = 0;
  23.             private int _left = 0;
  24.             private int _top = 0;
  25.             private decimal _width = 0;
  26.             private decimal _height = 0;
  27.             private System.Drawing.Point _location = new System.Drawing.Point();
  28.             public ReportImageConfig(int Id, int Left, int Top, decimal Width, decimal Height)
  29.             {
  30.                 _id = Id;
  31.                 _left = Left;
  32.                 _top = Top;
  33.                 _width = Width;
  34.                 _height = Height;
  35.                 _location.X = Left;
  36.                 _location.Y = _top;
  37.             }
  38.             public ReportImageConfig(string Field, int Left, int Top, decimal Width, decimal Height)
  39.             {
  40.                 _field = Field;
  41.                 _left = Left;
  42.                 _top = Top;
  43.                 _width = Width;
  44.                 _height = Height;
  45.                 _location.X = Left;
  46.                 _location.Y = _top;
  47.             }
  48.             public string Field
  49.             {
  50.                 get { return _field; }
  51.             }
  52.             public int Id
  53.             {
  54.                 get { return _id; }
  55.             }
  56.             public int Left
  57.             {
  58.                 get { return _left; }
  59.             }
  60.             public int Top
  61.             {
  62.                 get { return _top; }
  63.             }
  64.             public decimal Width
  65.             {
  66.                 get { return _width; }
  67.             }
  68.             public decimal Height
  69.             {
  70.                 get { return _height; }
  71.             }
  72.             public System.Drawing.Point Location
  73.             {
  74.                 get { return _location; }
  75.             }
  76.         }
复制代码
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-10-29 16:25:00
6#
回复 5楼mindrayguowei的帖子

这个问题需要使用 Table 进行占位,我做了一个简单demo供您参考:
19217.zip (28.27 KB, 下载次数: 108)
Demo1.gif
回复 使用道具 举报
yangjianlang
初级会员   /  发表于:2015-11-2 11:24:00
7#
Sub InsertImage(name As String)

    Dim sel_start As Integer
    Dim sel_end As Integer
    Dim image_id As Long
    Dim field_id As Long

    sel_start = Form1.TXTextControl1.selstart

    image_id = Form1.TXTextControl1.ObjectInsertAsChar(0, name, -1,
    100, 100, 0, 0)
    If image_id = 0 Then Exit Sub

    sel_end = Form1.TXTextControl1.selstart

    ' Select the image
    Form1.TXTextControl1.selstart = sel_start
    Form1.TXTextControl1.SelLength = sel_end - sel_start

    ' Put the image into a field and store the image's ID in the field
    If Form1.TXTextControl1.FieldInsert("赵志敬") Then
        field_id = Form1.TXTextControl1.FieldCurrent
        Form1.TXTextControl1.FieldData(field_id) = image_id
        Form1.TXTextControl1.FieldChangeable = False

        ' Finally store the path name in a global variable
        ImagePaths(field_id) = name
    Else
        ' Something's wrong, delete the inserted image
        Form1.TXTextControl1.ObjectDelete (image_id)
    End If

End Sub



这个是TX范例,应该也是可以的
回复 使用道具 举报
mindrayguowei
中级会员   /  发表于:2015-11-2 14:19:00
8#
楼上这个是ActiveX控件吧,我不是这个控件,没这些方法
回复 使用道具 举报
mindrayguowei
中级会员   /  发表于:2015-11-2 15:06:00
9#
回复 6楼iceman的帖子

我们讨论了以下,用表格的方式不可行。就没有别的办法了 吗? 这应该是比较基本的功能啊
回复 使用道具 举报
yangjianlang
初级会员   /  发表于:2015-11-2 19:50:00
10#
回复 8楼mindrayguowei的帖子

是ActiveX控件
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部