一.Tx Textcontrol如何禁用右键快捷菜单?

==》

添加txContent_TextContextMenuOpening事件,实现方式如下所示:

private void txContent_TextContextMenuOpening(object sender, TextContextMenuEventArgs e)
{
e.Cancel = true;
}

二.模版合并

1.在TxControl内容结尾处进行追加模版信息

如下所示:

  int length = txContent.Text.Length;

  this.txContent.Select(length, 0);

  if (FilePath.Contains(".tx"))

  this.txContent.Selection.Load(FilePath, TXTextControl.StreamType.InternalFormat);
  else
  this.txContent.Selection.Load(FilePath, TXTextControl.StreamType.MSWord);

2.在鼠标所在位置合并

实现方式如下:

/// <summary>
/// 光标处添加模版
/// </summary>
/// <param name="bytes">模版信息</param>
private void InsetTemplateToInputPosition(byte[] bytes)
{
if (bytes == null) return;

int input = this.txContent.InputPosition.TextPosition;
PubHelper.Instance.CreateDir(Application.StartupPath + "\\temp");
string path = Application.StartupPath + "\\temp\\" + Guid.NewGuid() + ".tx";
try
{
path = Helper.Instance.ByteConvertWord(bytes, path);
this.txContent.Selection.Load(path, TXTextControl.StreamType.InternalFormat);
}
catch
{
return;
}
finally
{
Helper.Instance.DeleteFile(path);
}
}

--------------------------------辅助方法如下所示-----------------------

/// <summary>
/// word文件转换二进制数据(用于保存数据库)
/// </summary>
/// <param name="wordPath">word文件路径</param>
/// <returns>二进制</returns>
public byte[] WordConvertByte(string wordPath)
{
if (!File.Exists(wordPath))
{
return null;
}
byte[] bytContent = null;
System.IO.FileStream fs = null;
System.IO.BinaryReader br = null;
try
{
fs = new FileStream(wordPath, System.IO.FileMode.Open);
br = new BinaryReader((Stream)fs);
bytContent = br.ReadBytes((Int32)fs.Length);
fs.Close();
br.Close();
}
catch
{
fs.Close();
br.Close();
return null;
}
return bytContent;
}

/// <summary>
///二进制数据转换为word文件
/// </summary>
/// <param name="data">二进制数据</param>
/// <param name="fileName">word文件名</param>
/// <returns>word保存的相对路径</returns>
public string ByteConvertWord(byte[] data, string fileName)
{
if (data == null) return string.Empty;

FileStream fs = null;
BinaryWriter br = null;
try
{
fs = new FileStream(fileName, FileMode.OpenOrCreate);
br = new BinaryWriter(fs);
br.Write(data, 0, data.Length);
br.Close();
fs.Close();
}
catch
{
br.Close();
fs.Close();
return string.Empty;
}
return fileName;
}

/// <summary>
/// 删除指定的文件
/// </summary>
/// <param name="fileName">文件路径+名称</param>
public void DeleteFile(string fileName)
{
if (File.Exists(fileName)) File.Delete(fileName);
}

3.换页合并模版(合并模版时内容不满一页的直接进入下一页)

实现方式如下:

int length = txContent.Text.Length;

this.txContent.InputPosition = new TXTextControl.InputPosition(length,
TXTextControl.TextFieldPosition.OutsideTextField);

this.txContent.Sections.Add(TXTextControl.SectionBreakKind.BeginAtNewPage);
this.txContent.Select(this.txContent.GetPages()[this.txContent.Pages - 1].Start + length, 0);

LoadTx();

==》

private void LoadTx()
{
if (FilePath.Contains(".tx"))
this.txContent.Selection.Load(FilePath, TXTextControl.StreamType.InternalFormat);
else
this.txContent.Selection.Load(FilePath, TXTextControl.StreamType.MSWord);
}

public void CombineTxToNextPage(TextControl control, string filePath)

{
if (!File.Exists(filePath)) return;
int length = control.Text.Length;
control.InputPosition = new TXTextControl.InputPosition(length,
TXTextControl.TextFieldPosition.OutsideTextField);
control.Sections.Add(TXTextControl.SectionBreakKind.BeginAtNewPage);
control.Select(control.GetPages()[control.Pages - 1].Start + length, 0);
//使用 Selection.Load 方法加载第二个文档
control.Selection.Load(filePath, TXTextControl.StreamType.InternalFormat);
}

三.实例如下

using System;
using System.Windows.Forms;
using TXTextControl;

namespace CombineDocs
{
public partial class Form1 : Form
{
#region load
private string FilePath = "..\\..\\ok.tx";

public Form1()
{
InitializeComponent();
}

private void LoadTx()
{
if (FilePath.Contains(".tx"))
this.txContent.Selection.Load(FilePath, TXTextControl.StreamType.InternalFormat);
else
this.txContent.Selection.Load(FilePath, TXTextControl.StreamType.MSWord);
}

private void Form1_Load(object sender, EventArgs e)
{
LoadTx();
}

#endregion

private void 加载1月总结文档ToolStripMenuItem_Click(object sender, EventArgs e)
{
int length = txContent.Text.Length;
this.txContent.Select(length, 0);

LoadTx();
}

private void 加载2月计划文档ToolStripMenuItem_Click(object sender, EventArgs e)
{
int length = txContent.Text.Length;

this.txContent.InputPosition = new TXTextControl.InputPosition(length,
TXTextControl.TextFieldPosition.OutsideTextField);

this.txContent.Sections.Add(TXTextControl.SectionBreakKind.BeginAtNewPage);
this.txContent.Select(this.txContent.GetPages()[this.txContent.Pages - 1].Start + length, 0);

LoadTx();
}

private void txContent_TextContextMenuOpening(object sender, TextContextMenuEventArgs e)
{
e.Cancel = true;
}
}
}

注意:此处只做Demo演示,不做代码规范处理......

最新文章

  1. applicationContext.xml
  2. 关于在DataGrid.RowDetailsTemplate中的控件查找不到的问题
  3. CSS3 transform 属性详解(skew, rotate, translate, scale)
  4. FSL - MELODIC
  5. mysql中的if判断
  6. 30天轻松学习javaweb_tomcat的虚拟目录设置
  7. Validform使用
  8. Spring Annotation注解进行aop的学习
  9. iOS开发工具箱
  10. Arrays和Collections 对于sort的不同实现原理
  11. Go语言库之strconv包(转载自--http://blog.csdn.net/alvine008/article/details/51283189)
  12. Python36 二进制文件读写问题
  13. VsVim的快捷键
  14. mysql 5.7 线程阻塞处理
  15. ActiveX多线程回调JavaScript
  16. Populating Next Right Pointers in Each Node II leetcode java
  17. Java lambda 表达式
  18. 【Docker】docker 入门以及一些常用指令
  19. NPM Scripts -- onchange parallelshell
  20. 【学习笔记】dp基础

热门文章

  1. Sublime Text插件:HTML+CSS+JAVASCRIPT+JSON快速格式化
  2. gpg --verify之&quot;Can&#39;t check signature: No public key&quot;
  3. BIOS设置
  4. JavaScript substring() 方法
  5. C++ Primer : 第九章 : vector变长、string的其他操作以及容器适配器
  6. SQLServer如何用T—SQL命令查询一个数据库中有哪些表
  7. puppet安装配置及使用
  8. URAL 1077 Travelling Tours(统计无向图中环的数目)
  9. ed编辑器使用
  10. SQL Debugging