當前位置:編程學習大全網 - 源碼下載 - C#中怎麽在richtextbox中實現表格功能,最好有段源代碼

C#中怎麽在richtextbox中實現表格功能,最好有段源代碼

richtextbox本身就有表格顯示的功能。妳在word中制作好表格,在復制到richtextbox中就Ok了。因為richtextbox支持rtf格式。rtf可以實現字體結構的不同程序間相互的轉移。

妳要想點個什麽事件後產生表格,就要自己寫了。使用DHTML COM

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace WindowsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

richTextBox2.Rtf = "{\\rtf1\\ansi\\ansicpg936\\deff0\\deflang1033\\deflangfe2052{\\fonttbl{\\f0\\fnil\\fprq2\\fcharset134 \\'cb\\'ce\\'cc\\'e5;}{\\f1\\fnil\\fcharset134 \\'cb\\'ce\\'cc\\'e5;}}\\viewkind4\\uc1\\trowd\\trgaph108\\trleft-108\\trbrdrt\\brdrs\\brdrw10 \\trbrdrl\\brdrs\\brdrw10 \\trbrdrb\\brdrs\\brdrw10 \\trbrdrr\\brdrs\\brdrw10 \\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx2732\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx5573\\clbrdrt\\brdrw15\\brdrs\\clbrdrl\\brdrw15\\brdrs\\clbrdrb\\brdrw15\\brdrs\\clbrdrr\\brdrw15\\brdrs \\cellx8414\\pard\\intbl\\kerning2\\f0\\fs21\\cell\\cell\\cell\\row\\intbl\\cell\\cell\\cell\\row\\pard\\lang2052\\kerning0\\f1\\fs18\\par}";

}

private void richTextBox1_TextChanged(object sender, EventArgs e)

{

//richTextBox2.Text = richTextBox1.Text;

richTextBox2.Text = richTextBox1.Rtf;

//toolStripStatusLabel1.Text = richTextBox1.Text;

}

private System.ComponentModel.IContainer components = null;

/// <summary>

/// 清理所有正在使用的資源。

/// </summary>

/// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗體設計器生成的代碼

/// <summary>

/// 設計器支持所需的方法 - 不要

/// 使用代碼編輯器修改此方法的內容。

/// </summary>

private void InitializeComponent()

{

this.richTextBox1 = new System.Windows.Forms.RichTextBox();

this.richTextBox2 = new System.Windows.Forms.RichTextBox();

this.statusStrip1 = new System.Windows.Forms.StatusStrip();

this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();

this.statusStrip1.SuspendLayout();

this.SuspendLayout();

//

// richTextBox1

//

this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.richTextBox1.Location = new System.Drawing.Point(0, 0);

this.richTextBox1.Name = "richTextBox1";

this.richTextBox1.Size = new System.Drawing.Size(292, 161);

this.richTextBox1.TabIndex = 0;

this.richTextBox1.Text = "";

this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);

//

// richTextBox2

//

this.richTextBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.richTextBox2.Location = new System.Drawing.Point(0, 157);

this.richTextBox2.Name = "richTextBox2";

this.richTextBox2.Size = new System.Drawing.Size(292, 91);

this.richTextBox2.TabIndex = 1;

this.richTextBox2.Text = "";

//

// statusStrip1

//

this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {

this.toolStripStatusLabel1});

this.statusStrip1.Location = new System.Drawing.Point(0, 251);

this.statusStrip1.Name = "statusStrip1";

this.statusStrip1.Size = new System.Drawing.Size(292, 22);

this.statusStrip1.TabIndex = 2;

this.statusStrip1.Text = "statusStrip1";

//

// toolStripStatusLabel1

//

this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";

this.toolStripStatusLabel1.Size = new System.Drawing.Size(131, 17);

this.toolStripStatusLabel1.Text = "toolStripStatusLabel1";

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(292, 273);

this.Controls.Add(this.statusStrip1);

this.Controls.Add(this.richTextBox2);

this.Controls.Add(this.richTextBox1);

this.Name = "Form1";

this.Text = "Form1";

this.statusStrip1.ResumeLayout(false);

this.statusStrip1.PerformLayout();

this.ResumeLayout(false);

this.PerformLayout();

}

#endregion

private System.Windows.Forms.RichTextBox richTextBox1;

private System.Windows.Forms.RichTextBox richTextBox2;

private System.Windows.Forms.StatusStrip statusStrip1;

private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;

}

}

需要什麽(圖片,表格)就復制到框1裏,框2就會顯示出代碼。這樣妳可能會更明白吧!

  • 上一篇:易語言怎麽制作遊戲鍵盤記錄器
  • 下一篇:昆山市陸家鎮組建陸家鎮生活垃圾分類?“紅色管家團”,妳有什麽好的建議?
  • copyright 2024編程學習大全網