实现如图所示效果:

实现代码如下所示:

注意,此处不做代码格式化处理...

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using TXTextControl;

namespace InsertImage
{
public partial class Form1 : Form
{
string FilePath1 = Application.StartupPath + "\\Image\\1.png";
string FilePath2 = Application.StartupPath + "\\Image\\2.png";
string FilePath3 = Application.StartupPath + "\\Image\\3.png";
string FilePath4 = Application.StartupPath + "\\Image\\4.png";

public Form1()
{
InitializeComponent();
}

private void 插入图片ToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(FilePath1);
// 完成TX中使用的度量单位缇(Twip)与.NET使用的度量单位像素(Pixel)的转换
Graphics g = txContent.CreateGraphics();
int iTwipsPerPixel = (int)(1600 / g.DpiX);
// 创建TX中的图片对象
System.Drawing.Image thumbImage = img.GetThumbnailImage(150, 150, null, System.IntPtr.Zero);
TXTextControl.Image image = new TXTextControl.Image(thumbImage);
// 设置图片ID
image.ID = 1001;
// 将图片插入到TextFrame中
txContent.Images.Add(image, txContent.InputPosition.TextPosition);
}

private void AddImage()
{
System.Drawing.Image img = System.Drawing.Image.FromFile(FilePath1);
System.Drawing.Image img2 = System.Drawing.Image.FromFile(FilePath2);
System.Drawing.Image img3 = System.Drawing.Image.FromFile(FilePath3);
System.Drawing.Image img4 = System.Drawing.Image.FromFile(FilePath4);

List<System.Drawing.Image> list = new List<System.Drawing.Image>();
list.Add(img);
list.Add(img2);
list.Add(img3);
list.Add(img4);

//AddOneImage(list);
AddOne2Image(list,200,200);
}

private void AddOne2Image(List<System.Drawing.Image> list, int width, int height)
{
System.Drawing.Image thumbImage = list[0].GetThumbnailImage(width, height, null, System.IntPtr.Zero);
TXTextControl.Image image = new TXTextControl.Image(thumbImage);

int txWidth = txContent.Width;
txContent.Images.Add(image, txContent.InputPosition.TextPosition);

this.txContent.Select(this.txContent.Text.Length, 0);
this.txContent.Selection.Text = " ";
}

public Table AddTable(int rows, int cols, int id)
{
this.txContent.Tables.Add(rows, cols, id);
Table table = this.txContent.Tables.GetItem(id);
return table;
}

private void AddOneImage(List<System.Drawing.Image> list)
{
for (int i = 0; i < list.Count; i++)
{
System.Drawing.Image thumbImage = list[i].GetThumbnailImage(200, 200, null, System.IntPtr.Zero);
TXTextControl.Image image = new TXTextControl.Image(thumbImage);

int width = txContent.Width;
int imageW = image.Size.Width;

txContent.Images.Add(image, txContent.InputPosition.TextPosition);

this.txContent.Select(this.txContent.Text.Length, 0);
this.txContent.Selection.Text = " ";
}
}

private void 插入ToolStripMenuItem_Click(object sender, EventArgs e)
{
AddImage();
}
}
}

TX Textcontrol 使用总结五——添加图片的更多相关文章

  1. C#如何在PDF文件添加图片印章

    文档中添加印章可以起一定的作用,比如,防止文件随意被使用,或者确保文档内容的安全性和权威性.C#添加图片印章其实也有很多实现方法,这里我使用的是免费的第三方软件Free Spire.PDF,向大家阐述 ...

  2. C# 给PDF添加图片背景

    C# 给PDF添加图片背景 今天要实现的是给PDF文件添加图片背景这个功能.PDF是近年来最流行的文件之一,无论是办公还是日常生活中都经常会用到,很多时候,PDF文件的背景色都是白色,看多了难免觉得累 ...

  3. TX Textcontrol 使用总结三——禁用右键、模版合并

    一.Tx Textcontrol如何禁用右键快捷菜单? ==> 添加txContent_TextContextMenuOpening事件,实现方式如下所示: private void txCon ...

  4. scrapy爬虫学习系列五:图片的抓取和下载

    系列文章列表: scrapy爬虫学习系列一:scrapy爬虫环境的准备:      http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_python_00 ...

  5. openLayers 4 canvas图例绘制,canvas循环添加图片,解决图片闪烁问题

    一.问题来源: 接触Openlayers 一段时间了,最近做了一个农业产业系统,项目中涉及到产业图例,最后考虑用canvas来绘制图例图像.当中带图片的图例移动时,图片会实现闪烁留白情况.闪烁是因为绘 ...

  6. 黄聪:phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护

    首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包含了PHPExcel.php和PHPExcel的文件夹,这个类文件和文件夹是我们需要的,把class ...

  7. C# 利用占位符替换word中的字符串和添加图片

    利用占位符替换word中的字符串和添加图片   ///<summary>         /// 替换word模板文件内容,包括表格中内容         /// 调用如下:WordStr ...

  8. pyside 为窗口添加图片

    有时我们需要添加一些图片到窗口上,下面给一个通过QLable实现的方法. 这里需要注意的是,当你启用多线程时,方法调用的setPixmap,会导致qt报出一个线程安全错误. 因此,让这个绘图工作尽量在 ...

  9. UILabel添加图片之富文本的简单应用

    若想对UILabel添加图片,那么就需要使用NSMutableAttributedString来定义先定义一个普通的label UILabel *lab = [[UILabel alloc]initW ...

随机推荐

  1. linux,下载与安装

    1.下载地址 1.网易开源镜像站 http://mirrors.163.com 2.centos 官方站 http://www.centos.org 2.虚拟机 VirtualBox  ------- ...

  2. linux 安装redis

    1:首先命令行下载安装包 wget http://download.redis.io/releases/redis-2.8.13.tar.gz 2:进行解压 tar xzf redis-2.8.13. ...

  3. 238. Product of Array Except Self

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  4. csu 1604 SunnyPig (bfs)

    Description SunnyPig is a pig who is much cleverer than any other pigs in the pigpen. One sunny morn ...

  5. bootStrap-2

    全局样式: 1.移除Body的margin声明: 2.设置Body的背景色为白色: 3.为排版设置了基本的字体,字号和行高: 4.设置全局连接颜色,且当连接处于悬浮:hover状态时,才会显示下划线样 ...

  6. ubuntu 双屏问题的解决方案

    ubuntu有一个很让人头疼的问题就是它默认开启双屏.只要你有两个显示器接口,即使你没有两块屏幕,它也是按照双屏幕去显示. 这就会造成一些很让人无语的问题,比如,恰好跳到你没有的那个屏幕就可能导致无法 ...

  7. kafka的推和拉的问题

    之前学习过这一问题,但是面试又被问道了.再次记录下 推还是拉? Kafka最初考虑的问题是,customer应该从brokes拉取消息还是brokers将消息推送到consumer,也就是pull还p ...

  8. CSS 通用原子类

    /*文字排版*/.f10 { font-size: 10px; }.f11 { font-size: 11px; }.f12 { font-size: 12px; }.f13 { font-size: ...

  9. C++ 实用的小程序

    1. 打开test_ids.txt 将里面的东西添加"1_",然后另存为test_ids_repaired.txt #include <iostream> #inclu ...

  10. eclipse cdt代码悬停窗口背景颜色设置(转载)

    在eclipse中编写C++代码时,有一个很方便的功能,是当鼠标停放在某一个函数或变量上不同时,会出现一个悬停框,显示该函数或变量的声明 体.但是, 从Ubuntu 10.04之后,这个悬停框便出现了 ...