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 ...
随机推荐
- hdu 2335 Containers
水题,就不解释了,不过这个题有一点很好,就是枚举的时候,枚举宽,也就是列数,因为这样才能越来越接近正方形 #include<cstdio> #include<cstring> ...
- POJ 1502 MPI Maelstrom
MPI Maelstrom Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Total ...
- c 函数及指针学习 6
不完整声明 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 /* 方法一 */ struct tag_a{ ...
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- spark_updateStateByKey
java核心代码 JavaPairDStream<String, Integer> wordCounts = pair.updateStateByKey(new Function2< ...
- POJ 2186 Popular Cows(强连通)
Popular Cows Time Limit: 2000MS Memo ...
- MySQL性能参数详解 - max_connect_errors
max_connect_errors是一个MySQL中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码的情况.max_connect_errors的值与性能并无太大关系. 默认情 ...
- Git连接Github
环境:Ubuntu Server 12.04 安装Git apt-get install git git-core 配置本机Git git config --global user.name &quo ...
- Win10如何设置相关性
为什么要设置相关性? 有一些老的游戏或者程序,没有针对多核cpu进行优化,运行的时候会出现卡顿,这个时候需要通过相关性的设置,让程序只使用一个cpu核心. 怎么设置相关性? win10以前的系统直接打 ...
- Draw a Border around any C# Winform Control
public class MyGroupBox : GroupBox { protected override void OnPaint(PaintEventArgs e) { base.OnPain ...