一.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. addcontentView之后如何让这个view消失掉

    Dia dialog ; public void go(View view){ dialog = (Dia) getLayoutInflater().inflate(R.layout.main, nu ...

  2. mysql 操作突然断网,MySQL: “lock wait timeout exceeded”

    show processlist;//显示所有进程select * from information_schema.innodb_trx;//查询锁的进程-- kill 310;//杀掉锁进程

  3. tyvj1014 - 乘法游戏 ——记忆化搜索DP

    题目链接:https://www.tyvj.cn/Problem_Show.aspx?id=1014 f[i][j]表示区间[i,j]所得到的最小值. 不断地划分区间,把结果保存起来. #includ ...

  4. Zuoye for guo

      A  B  C  D  E  A  -  3  6  10  13  B  -  -  5  9  12  C  -  -  -  10  13  D  -  -  -  -  9  E  -  ...

  5. tomcat的配置详解:[1]tomcat绑定域名

    转自:http://jingyan.baidu.com/article/7e440953dc096e2fc0e2ef1a.html tomcat的配置详解:[1]tomcat绑定域名分步阅读 在jav ...

  6. Unity Shader _Time

    _Time是个4维向量,跟Unity3D中的deltaTime(这是个一维的,数值)不同. float4 _Time : Time (t/20, t, t*2, t*3), use to animat ...

  7. dede后台栏目文章问题

    栏目下的子栏目文档,并不记在主栏目文档数中,让我一直以为程序错误.

  8. JavaScript的事件绑定及深入

     事件绑定分为两种:一种是传统事件绑定(内联模型,脚本模型),一种是现代事件绑定 (DOM2 级模型).现代事件绑定在传统绑定上提供了更强大更方便的功能. 一.传统事件绑定的问题传统事件绑定有内联模型 ...

  9. SQL Server 表所在的文件组

    SELECT  o.[name] ,-- o.[type], i.[name], i.[index_id],         f.[name] FROM    sys.indexes i        ...

  10. Storyboard 跳转 和 传值

    因为苹果推 Storyboard 而且 目前来看, Apple Watch 也是用 Storyboard 就知道, 明天应用估计都是 Storyboard 的天下了. (水平有限, 不对之处在所难免, ...