TX Textcontrol 使用总结五——添加图片
实现如图所示效果:

实现代码如下所示:
注意,此处不做代码格式化处理...
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 使用总结五——添加图片的更多相关文章
- C#如何在PDF文件添加图片印章
文档中添加印章可以起一定的作用,比如,防止文件随意被使用,或者确保文档内容的安全性和权威性.C#添加图片印章其实也有很多实现方法,这里我使用的是免费的第三方软件Free Spire.PDF,向大家阐述 ...
- C# 给PDF添加图片背景
C# 给PDF添加图片背景 今天要实现的是给PDF文件添加图片背景这个功能.PDF是近年来最流行的文件之一,无论是办公还是日常生活中都经常会用到,很多时候,PDF文件的背景色都是白色,看多了难免觉得累 ...
- TX Textcontrol 使用总结三——禁用右键、模版合并
一.Tx Textcontrol如何禁用右键快捷菜单? ==> 添加txContent_TextContextMenuOpening事件,实现方式如下所示: private void txCon ...
- scrapy爬虫学习系列五:图片的抓取和下载
系列文章列表: scrapy爬虫学习系列一:scrapy爬虫环境的准备: http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_python_00 ...
- openLayers 4 canvas图例绘制,canvas循环添加图片,解决图片闪烁问题
一.问题来源: 接触Openlayers 一段时间了,最近做了一个农业产业系统,项目中涉及到产业图例,最后考虑用canvas来绘制图例图像.当中带图片的图例移动时,图片会实现闪烁留白情况.闪烁是因为绘 ...
- 黄聪:phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包含了PHPExcel.php和PHPExcel的文件夹,这个类文件和文件夹是我们需要的,把class ...
- C# 利用占位符替换word中的字符串和添加图片
利用占位符替换word中的字符串和添加图片 ///<summary> /// 替换word模板文件内容,包括表格中内容 /// 调用如下:WordStr ...
- pyside 为窗口添加图片
有时我们需要添加一些图片到窗口上,下面给一个通过QLable实现的方法. 这里需要注意的是,当你启用多线程时,方法调用的setPixmap,会导致qt报出一个线程安全错误. 因此,让这个绘图工作尽量在 ...
- UILabel添加图片之富文本的简单应用
若想对UILabel添加图片,那么就需要使用NSMutableAttributedString来定义先定义一个普通的label UILabel *lab = [[UILabel alloc]initW ...
随机推荐
- could not write file C:\DOCUME~1\ADMIN
今天碰到一个错误,android模拟器无法启动,错误提示如下: NAND: could not write file C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\\Andro ...
- haar-like特征(转载)
浅析人脸检测之Haar分类器方法 [补充] 这是我时隔差不多两年后, 回来编辑这篇文章加的这段补充, 说实话看到这么多评论很是惊讶, 有很多评论不是我不想回复, 真的是时间久了, 很多细节我都忘记了 ...
- 110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- TextView所有属性
android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none/web/email/phone/map/all) android: ...
- com.google.guava 包解析 ——Google Guava官方教程(中文版)
全网址 http://ifeve.com/google-guava/ 竹子博客: http://www.cnblogs.com/peida/archive/2013/06/08/ ...
- XUtils解析
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ...
- SQL注入测试平台 SQLol -6.CHALLENGES挑战
SQLol上面的挑战共有14关,接下来我们一关一关来突破. Challenge 0 目的是让查询返回所有的用户名,而不是只有一个. SELECT username FROM users WHERE u ...
- Codeforces 106 C 多重背包
题目链接:http://codeforces.com/problemset/problem/106/C 根据题意列出式子,设每种蛋糕做了xi个,则对于每种材料bi*xi<=ai. 对于dough ...
- Linux内核编译和运行(转-段玉磊)
内核获取网站:https://www.kernel.org/pub/linux/kernel/ 步骤如下: 1.打开终端,更改用户权限为root.具体做法是在终端输入sudo su,然后按提示输入密码 ...
- jQuery使用伪递归重复执行动画
使用setInterval()来重复执行动画,会因为动画执行过程的时候,setInterval()的时间依然是在走的,所以会导致动画的调用时间不理想,因此只能使用递归来重复执行动画. // 首页LOG ...