mindrayguowei 发表于 2015-10-28 15:19:00

插入图片的时同时插入描述图片的文字

通过程序向TextControl中插入图片,有些图片可能有相应的图片描述, 图片和文字都来自于数据库。
现在插入图片是根据配置好的图片坐标插入到控件的相应位置,现在要插入文字,要求显示在图片下方。

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


TextField textField = new TextField("赵志敬");
_textControl.InputPosition = new InputPosition(new System.Drawing.Point(config.Left, config.Top + (int)config.Height));
_textControl.TextFields.Add(textField);


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

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


for (int i = 0; i < _imagePathList.Count; i++)
      {
            string fileName = _imagePathList;
            ReportImageConfig config = reportImageConfigList;


            Image image = new Image(fileName, 5);
            image.SaveMode = ImageSaveMode.SaveAsData;
            System.Drawing.Image img = System.Drawing.Image.FromFile(fileName);

            int vScaleFactor = Convert.ToInt32(config.Height / (img.Height * TwipsPerPixel) * 100);
            int hScaleFactor = Convert.ToInt32(config.Width / (img.Width * TwipsPerPixel) * 100);

            img.Dispose();
            img = null;

            image.HorizontalScaling = hScaleFactor;
            image.VerticalScaling = vScaleFactor;

            _textControl.Images.Add(image, config.Location, ImageInsertionMode.DisplaceCompleteLines);


            //TextField textField = new TextField("赵志敬");
            //_textControl.InputPosition = new InputPosition(new System.Drawing.Point(config.Left, config.Top + (int)config.Height));
            //_textControl.TextFields.Add(textField);

      }

      class ReportImageConfig
      {
            private string _field = string.Empty;
            private int _id = 0;
            private int _left = 0;
            private int _top = 0;
            private decimal _width = 0;
            private decimal _height = 0;

            private System.Drawing.Point _location = new System.Drawing.Point();

            public ReportImageConfig(int Id, int Left, int Top, decimal Width, decimal Height)
            {
                _id = Id;
                _left = Left;
                _top = Top;
                _width = Width;
                _height = Height;

                _location.X = Left;
                _location.Y = _top;
            }

            public ReportImageConfig(string Field, int Left, int Top, decimal Width, decimal Height)
            {
                _field = Field;
                _left = Left;
                _top = Top;
                _width = Width;
                _height = Height;

                _location.X = Left;
                _location.Y = _top;
            }

            public string Field
            {
                get { return _field; }
            }

            public int Id
            {
                get { return _id; }
            }

            public int Left
            {
                get { return _left; }
            }

            public int Top
            {
                get { return _top; }
            }

            public decimal Width
            {
                get { return _width; }
            }

            public decimal Height
            {
                get { return _height; }
            }

            public System.Drawing.Point Location
            {
                get { return _location; }
            }
      }

iceman 发表于 2015-10-29 16:25:00

回复 5楼mindrayguowei的帖子

这个问题需要使用 Table 进行占位,我做了一个简单demo供您参考:


效果图:
attachimg]18460

不需要显示 table 边框隐藏即可。

yangjianlang 发表于 2015-11-2 11:24:00

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

楼上这个是ActiveX控件吧,我不是这个控件,没这些方法

mindrayguowei 发表于 2015-11-2 15:06:00

回复 6楼iceman的帖子

我们讨论了以下,用表格的方式不可行。就没有别的办法了 吗? 这应该是比较基本的功能啊

yangjianlang 发表于 2015-11-2 19:50:00

回复 8楼mindrayguowei的帖子

是ActiveX控件
页: [1] 2
查看完整版本: 插入图片的时同时插入描述图片的文字