附件:http://files.cnblogs.com/xe2011/richTextBox_InsertTable.rar

插入表格

       /// <summary>
/// 插入表格
/// </summary>
/// <param name="richTextBox"></param>
/// <param name="col">行</param>
/// <param name="row">列</param>
/// <param name="AutoSize">=TRUE:自动设置每个单元格的大小</param>
private void InsertTable(RichTextBox richTextBox,int col, int row,bool AutoSize)
{
StringBuilder rtf = new StringBuilder();
rtf.Append(@"{\rtf1 "); //int cellWidth = 1000;//col.1 width =1000
int cellWidth = ; if (AutoSize)
//滚动条出现时 (richTextBox.ClientSize.Width - 滚动条的宽 /列的个数)*15
cellWidth = (richTextBox.ClientSize.Width / row) * ; //15 当ROW值越大 结果差距越大 Text = cellWidth.ToString() ;
for (int i = ; i < col; i++)
{
rtf.Append(@"\trowd");
for (int j = ; j <= row; j++)
rtf.Append(@"\cellx" + (j * cellWidth).ToString());
rtf.Append(@"\intbl \cell \row"); //create row
}
rtf.Append(@"\pard");
rtf.Append(@"}");
richTextBox.SelectedRtf = rtf.ToString();
}

扩展的richTextBox

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms; namespace richTextBoxTableClass
{
public class CustomRichTextBox : RichTextBox
{ ///支持表格正确粘贴
// P/Invoke declarations
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LoadLibrary(string path); private static IntPtr moduleHandle; protected override CreateParams CreateParams
{
get
{
if (moduleHandle == IntPtr.Zero)
{
moduleHandle = LoadLibrary("msftedit.dll");
if ((long)moduleHandle < 0x20)
{
throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not load Msftedit.dll");
}
} CreateParams createParams = base.CreateParams;
createParams.ClassName = "RichEdit50W";
if (this.Multiline)
{
if (((this.ScrollBars & RichTextBoxScrollBars.Horizontal) != RichTextBoxScrollBars.None) &&!base.WordWrap)
{
createParams.Style |= 0x100000;
if ((this.ScrollBars & ((RichTextBoxScrollBars)0x10)) != RichTextBoxScrollBars.None)
{
createParams.Style |= 0x2000;
}
}
if ((this.ScrollBars & RichTextBoxScrollBars.Vertical) != RichTextBoxScrollBars.None)
{
createParams.Style |= 0x200000;
if ((this.ScrollBars & ((RichTextBoxScrollBars)0x10)) != RichTextBoxScrollBars.None)
{
createParams.Style |= 0x2000;
}
}
}
if ((BorderStyle.FixedSingle == base.BorderStyle) && ((createParams.Style & 0x800000) != ))
{
createParams.Style &= -;
createParams.ExStyle |= 0x200;
}
return createParams;
}
} }
}

CustomRichTextBox.CS

调用

        private void button1_Click(object sender, EventArgs e)
{
InsertTable(richTextBox1, , , false);
InsertTable(richTextBox51,, , false);
}

richTextBox插入表格的更多相关文章

  1. richTextBox插入表格 完整版

    附件 http://files.cnblogs.com/xe2011/richTextBox_InsertTable_Full.rar 调用 richTextBoxTableDlg dlg = new ...

  2. 地图中插入表格——ArcMap篇

    在制作专题图的过程中,不但要有地理要素表示空间位置,经常还要在图的周围制作一些表格数据.这里对ArcMap中的插入方法进行总结. 方法一:插入对象 利用菜单中的"插入"-" ...

  3. Word里插入表格不带左右边框

    插入表格后选中,然后开始-----段落------选择右下角的边框设置,选择无左右边框.

  4. C# 操作Word文本框——插入表格/读取表格/删除表格

    在文本框中,我们可以操作很多元素,如文本.图片.表格等,在本篇文章中将着重介绍如何插入表格到文本框,插入的表格我们可以对表格进行格式化操作来丰富表格内容.此外,对于文本框中的表格内容,我们也可以根据需 ...

  5. 13LaTeX学习系列之---LaTeX插入表格

    目录 目录 前言 (一)插入表格的基础语法 1.说明 2.源代码 3.输出效果 (二)查看文档 目录 本系列是有关LaTeX的学习系列,共计19篇,本章节是第13篇. 前一篇:12LaTeX学习系列之 ...

  6. 获取刚刚插入表格的这条信息的自增ID

    获取刚刚插入表格的这条信息的自增ID var conn=getConnection(); var msql="INSERT INTO " + table +" (&quo ...

  7. Ueditor 1.4.3 插入表格后无边框无颜色,不能正常显示

    在使用Ueditor 插入表格的功能时,发现插入时正常. 但保存到后台后再取出来,表格不能正常显示.查看保存的html代码,发现保存时并未给table 添加border属性.以致于再次取出来时,不能正 ...

  8. java POI往word文档中指定位置插入表格

    1.Service  demo import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.a ...

  9. WPF RichTextBox 插入回车

    richtextbox插入回车,开始是这样写的,在win7下运行时没有问题: MyMessageBox.CaretPosition.InsertLineBreak(); MyMessageBox.Ca ...

随机推荐

  1. C++引用之引用的使用

    一旦一个引用被声明,则该引用名就只能作为目标变量名的一个别名来使用,所以,不能再把该引用名作为其他变量名的别名,任何对该引用的赋值就是对该引用对应的目标变量名的赋值. 对引用求地址就是对目标变量求地址 ...

  2. Http 与 Socket 区别

    HTTP:超文本传输协议,首先它是一个协议,并且是基于TCP/IP协议基础之上的应用层协议.TCP/IP协议是传输层协议,主要解决数据如何在网络中传输,HTTP是应用层协议,主要解决如何包装数据.HT ...

  3. Ubuntu使用wget下载jdk问题

    使用以下命令可下载成功,否则下载下来的可能是一个html文档. wget --no-cookies --no-check-certificate --header "Cookie:gpw_e ...

  4. Python还是很重要的,不能丢。学习IF和WHILE

    number = 23 guess = int(input('Enter an interger : ')) if guess == number: print('Congratulations, y ...

  5. 内存卡的class是什么意思 内存卡class的5个等级

    内存卡的class是什么意思 SD协会针对TF内存卡(SDHC)的传输规范:传输速度(写入速度及读取速度的最低速度)被定义为Class2(2MB/sec).Class4(4MB/sec).Class6 ...

  6. Delphi xe10下载(包含破解补丁和破解视频)

    软件名称:RAD Studio 10 Seattle软件大小:7.18 GB RAD Studio 10 Seattle官方下载地址:http://altd.embarcadero.com/downl ...

  7. DIV 清除样式浮动万能代码

            .talk {             width: 100%;             margin: 10px 0;         }         .talk:after { ...

  8. WCF Concurrency (Single, Multiple, and Reentrant) and Throttling

    http://www.codeproject.com/Articles/89858/WCF-Concurrency-Single-Multiple-and-Reentrant-and Introduc ...

  9. BZOJ_1208_&_Codevs_1258_[HNOI2004]_宠物收养所_(平衡树/set)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1208 (据说codevs要更新?就不放codevs的地址了吧...) 有宠物和人,每个单位都有 ...

  10. 水题:HDU 5119 Happy Matt Friends

    Matt has N friends. They are playing a game together.Each of Matt's friends has a magic number. In t ...