using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace AppendTest { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.RichTextBox rtfChat; private System.Windows.Forms.RichTextBox rtfSend; private System.Windows.Forms.Button buttonSend; private System.Windows.Forms.Button buttonRTF; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); rtfSend.Focus(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.rtfChat = new System.Windows.Forms.RichTextBox(); this.rtfSend = new System.Windows.Forms.RichTextBox(); this.buttonSend = new System.Windows.Forms.Button(); this.buttonRTF = new System.Windows.Forms.Button(); this.SuspendLayout(); // // rtfChat // this.rtfChat.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.rtfChat.Location = new System.Drawing.Point(8, 16); this.rtfChat.Name = "rtfChat"; this.rtfChat.Size = new System.Drawing.Size(440, 160); this.rtfChat.TabIndex = 0; this.rtfChat.Text = ""; // // rtfSend // this.rtfSend.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.rtfSend.Location = new System.Drawing.Point(8, 184); this.rtfSend.Name = "rtfSend"; this.rtfSend.Size = new System.Drawing.Size(288, 32); this.rtfSend.TabIndex = 1; this.rtfSend.Text = ""; this.rtfSend.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rtfSend_KeyDown); // // buttonSend // this.buttonSend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonSend.Location = new System.Drawing.Point(296, 184); this.buttonSend.Name = "buttonSend"; this.buttonSend.Size = new System.Drawing.Size(72, 32); this.buttonSend.TabIndex = 2; this.buttonSend.Text = "Send"; this.buttonSend.Click += new System.EventHandler(this.buttonSend_Click); // // buttonRTF // this.buttonRTF.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRTF.Location = new System.Drawing.Point(376, 184); this.buttonRTF.Name = "buttonRTF"; this.buttonRTF.Size = new System.Drawing.Size(75, 32); this.buttonRTF.TabIndex = 3; this.buttonRTF.Text = "RTF"; this.buttonRTF.Click += new System.EventHandler(this.buttonRTF_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(456, 222); this.Controls.Add(this.buttonRTF); this.Controls.Add(this.buttonSend); this.Controls.Add(this.rtfSend); this.Controls.Add(this.rtfChat); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void buttonSend_Click(object sender, System.EventArgs e) { SendMessage(); } private void rtfSend_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == System.Windows.Forms.Keys.Enter) { SendMessage(); e.Handled = true; } } private void SendMessage() { Console.WriteLine(rtfSend.Rtf); Color color1 = Color.Red; Color color2 = Color.Black; rtfChat.SelectionColor = color1; rtfChat.AppendText("Nickname: "); rtfChat.SelectionColor = color2; rtfChat.AppendText(rtfSend.Text + "\n"); rtfSend.Clear(); } private void buttonRTF_Click(object sender, System.EventArgs e) { Color color1 = Color.Red; rtfChat.SelectionColor = color1; rtfChat.AppendText("Nickname: "); rtfChat.SelectedRtf = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq1\fcharset0 Courier New;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}{\colortbl ;\red0\green0\blue255;}\viewkind4\uc1\pard\cf1\f0\fs20 private\cf0 \cf1 void\cf0 rtfSend_KeyDown(\cf1 object\cf0 sender, System.Windows.Forms.KeyEventArgs e)\f1\fs17\par}"; } } }