📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace XHTML_Displaying_Rich_Text_Box
{
/// <summary>
/// This is a simple application to show off the functionality of a RichTextBox
/// designed to support limited XHTML display.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBoxInput;
private System.Windows.Forms.Label labelInput;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBoxErrors;
private System.Windows.Forms.Button button2;
private RichTextBoxSupportsXHTML.RichTextBoxSupportsXHTML rtfOutput;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBoxInput = new System.Windows.Forms.TextBox();
this.labelInput = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.textBoxErrors = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.rtfOutput = new RichTextBoxSupportsXHTML.RichTextBoxSupportsXHTML();
this.SuspendLayout();
//
// textBoxInput
//
this.textBoxInput.AcceptsReturn = true;
this.textBoxInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxInput.BackColor = System.Drawing.SystemColors.Info;
this.textBoxInput.Location = new System.Drawing.Point(144, 8);
this.textBoxInput.Multiline = true;
this.textBoxInput.Name = "textBoxInput";
this.textBoxInput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBoxInput.Size = new System.Drawing.Size(640, 224);
this.textBoxInput.TabIndex = 0;
this.textBoxInput.Text = "";
//
// labelInput
//
this.labelInput.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelInput.Location = new System.Drawing.Point(8, 8);
this.labelInput.Name = "labelInput";
this.labelInput.Size = new System.Drawing.Size(128, 128);
this.labelInput.TabIndex = 1;
this.labelInput.Text = "Enter well-formed XHTML in this box. Hit the display button to translate the XHT" +
"ML into Rich Text and display it in the modified RichTextBox below.";
//
// button1
//
this.button1.Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button1.Location = new System.Drawing.Point(8, 144);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 40);
this.button1.TabIndex = 2;
this.button1.Text = "Display";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBoxErrors
//
this.textBoxErrors.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxErrors.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.textBoxErrors.Location = new System.Drawing.Point(8, 688);
this.textBoxErrors.Multiline = true;
this.textBoxErrors.Name = "textBoxErrors";
this.textBoxErrors.ReadOnly = true;
this.textBoxErrors.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBoxErrors.Size = new System.Drawing.Size(776, 72);
this.textBoxErrors.TabIndex = 4;
this.textBoxErrors.Text = "Translation errors will be printed here.";
//
// button2
//
this.button2.Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button2.Location = new System.Drawing.Point(8, 192);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(128, 40);
this.button2.TabIndex = 5;
this.button2.Text = "View Readme";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// rtfOutput
//
this.rtfOutput.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.rtfOutput.BackColor = System.Drawing.SystemColors.Window;
this.rtfOutput.Location = new System.Drawing.Point(8, 240);
this.rtfOutput.Name = "rtfOutput";
this.rtfOutput.ReadOnly = true;
this.rtfOutput.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.rtfOutput.Size = new System.Drawing.Size(776, 440);
this.rtfOutput.TabIndex = 6;
this.rtfOutput.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(792, 766);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.rtfOutput,
this.button2,
this.textBoxErrors,
this.button1,
this.labelInput,
this.textBoxInput});
this.Name = "Form1";
this.Text = "XHTML Displaying Rich Text Box";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
/// <summary>
/// This event handler sets the input XHTML to the Xhtml property on the
/// RichTextBoxSupportsXHTML. The setting of that property translates the
/// XHTML into RTF code and outputs it to the box.
/// </summary>
private void button1_Click(object sender, System.EventArgs e)
{
rtfOutput.Xhtml = textBoxInput.Text;
textBoxErrors.Text = "";
foreach (string message in rtfOutput.Errors)
{
textBoxErrors.Text += "ERROR: " + message + System.Environment.NewLine;
}
if (textBoxErrors.Text == "")
{
textBoxErrors.Text = "No errors.";
}
}
private void button2_Click(object sender, System.EventArgs e)
{
StreamReader reader = new StreamReader(new FileStream("..\\..\\readme.xml", FileMode.Open));
textBoxInput.Text = reader.ReadToEnd();
rtfOutput.Xhtml = textBoxInput.Text;
reader.Close();
textBoxErrors.Text = "";
foreach (string message in rtfOutput.Errors)
{
textBoxErrors.Text += "ERROR: " + message + System.Environment.NewLine;
}
if (textBoxErrors.Text == "")
{
textBoxErrors.Text = "No errors.";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -