一.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演示,不做代码规范处理......

TX Textcontrol 使用总结三——禁用右键、模版合并的更多相关文章

  1. 新版【CefSharp】 禁用右键菜单 43.00+

    原文:新版[CefSharp] 禁用右键菜单 43.00+ 禁用右键菜单其实是很容易的.主就要是实现一个接口 IMenuHandler ,这个接口有一个  OnBeforeContextMenu 的方 ...

  2. 【CefSharp】 禁用右键菜单 与 控制弹出窗口的方式(限版本39.0.0.1)

    这周没什么时间,一开始就在忙一些CefSharp的事情,Win10的研究就放了下来,CefSharp的资料挺少的,但好在是开源的,可以我们便宜的折腾.因为两个的内容都不多,我就合成一篇文章啦. 这还里 ...

  3. WebBrowser 禁用右键

    禁用错误脚本提示 将 WebBrowser控件的 ScriptErrorsSuppressed 设为 true 禁用右键菜单 将 WebBrowser 的 IsWebBrowserContextMen ...

  4. TX Textcontrol 使用总结六——常用属性设置

    1.字体设置 Tx textcontrol字体设置以版本22为例,直接设置FontSize =int,字体大小将小于正常其他控件字体设置.应做如下处理(仅供参考) this.textControl1. ...

  5. jquery禁用右键单击功能屏蔽F5刷新

    1.禁用右键单击功能$(document).ready(function() { $(document).bind("contextmenu",function(e) { aler ...

  6. jquery禁用右键、文本选择功能、复制按键的实现

    同时适合IE.firefox.谷歌浏览器下适用,经过筛选代码如下 //禁用右键.文本选择功能.复制按键 $(document).bind(“contextmenu”,function(){return ...

  7. JS input文本框禁用右键和复制粘贴功能的代码

    代码如下: function click(e) { if (document.all) { ||||) { oncontextmenu='return false'; } } if (document ...

  8. 禁止选择文本和禁用右键 v1.0

    var zhonghao={ //绑定事件 myAddEvent: function(obj, sEvent, fn){if(obj.attachEvent){obj.attachEvent('on' ...

  9. jquery禁用右键、文本选择功能、刷新

    //禁用右键.文本选择功能.刷新 $(document).bind(“contextmenu”,function(){return false;}); $(document).bind(“select ...

随机推荐

  1. word文档快速取消图片的链接

    快捷键Ctrl+Shift+F9 首先,Ctrl+A全选文章或者用鼠标拖动的方法选中部分文中: 批量删除word文档中的超级链接然后,同时按下键盘上的Ctrl+Shift+F9. 效果就出现了! 宏方 ...

  2. UVa 12558 - Egyptian Fractions (HARD version)

    题目大意: 给出一个真分数,把它分解成最少的埃及分数的和.同时给出了k个数,不能作为分母出现,要求解的最小的分数的分母尽量大. 分析: 迭代加深搜索,求埃及分数的基础上,加上禁用限制就可以了.具体可以 ...

  3. poj 1475 uva 589 - Pushing Boxes

    题目大意 人推箱子从起点到终点,要求推箱子的次数最少,并打印出来人移动的路径. 题目分析 对于箱子进行宽搜的同时,要兼顾人是否能够把箱子推到相应的位置 每一次对箱子bfs 然后对人再bfs #incl ...

  4. pstack使用和原理

    前言: 最近小组在组织<<深入剖析Nginx>>的读书会, 里面作者提到了pstack这个工具. 之前写JAVA程序, 对jstack这个工具, 非常的喜欢, 觉得很有用. 于 ...

  5. Codeforces Round #372 (Div. 2) A B C 水 暴力/模拟 构造

    A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. ipconfig /flushdns 解释

    当我们一域名的形式访问过目标网站后,该网站的域名和IP地址对应关系就会自动保存到本地工作站的DNS缓存列表中,如果以后再次访问该域名,浏览器就会先访问DNS缓存列表中的信息.但是,如果被访问网站的域名 ...

  7. 嵌入式Linux C笔试题积累(转)

    http://blog.csdn.net/h_armony/article/details/6764811 1.   嵌入式系统中断服务子程序(ISR) 中断是嵌入式系统中重要的组成部分,这导致了很 ...

  8. 常见半监督方法 (SSL) 代码总结

    经典以及最新的半监督方法 (SSL) 代码总结 最近因为做实验需要,收集了一些半监督方法的代码,列出了一个清单: 1. NIPS 2015 Semi-Supervised Learning with ...

  9. lua 初接触 --- The first time use Lua for programing

    The first time use Lua for programing Wang Xiao 1. 关于 lua 的变量类型:  lua 变量的定义与matlab有点不同: local d , f ...

  10. caffe: compile error : undefined reference to `cv::imread(cv::String const&, int)' et al.

    when I compile caffe file : .build_debug/lib/libcaffe.so: undefined reference to `cv::imread(cv::Str ...