using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp2 { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } // Here is Form1.cs namespace WindowsFormsApp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void richTextBox1_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { do_it(); } private void Form1_Load(object sender, EventArgs e) { } } } // Here is Form1.Designer.cs namespace WindowsFormsApp2 { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (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.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // richTextBox1 // this.richTextBox1.Location = new System.Drawing.Point(53, 106); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(259, 196); this.richTextBox1.TabIndex = 0; this.richTextBox1.Text = ""; this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged); // // button1 // this.button1.Location = new System.Drawing.Point(57, 17); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(254, 55); this.button1.TabIndex = 1; this.button1.Text = "Display table"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.button1); this.Controls.Add(this.richTextBox1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.Button button1; } } // Here is myForm1.cs, the partial class. namespace WindowsFormsApp2 { public partial class Form1 : Form { private void do_it() { StringBuilder outputline = new StringBuilder(100); String s; s = utility.times_table(12); outputline.Append(s); this.richTextBox1.Text = outputline.ToString(); } } } //utility.cs static class utility { public static string times_table(int n) { string s = "" ; for (int i=1;i<=n;i++) { s += String.Format("{0,3}",i); s += " * "; s += String.Format("{0,3}",n); s += " = "; s += String.Format("{0,3}",i*n); s += "\n"; } return(s); } }