From 731c9279e4e3d5c978001330d0261589b916c8a2 Mon Sep 17 00:00:00 2001 From: EggMan20339 <99349302+EggMan20339@users.noreply.github.com> Date: Mon, 5 Feb 2024 22:30:11 -0500 Subject: [PATCH] Ch5 try it --- Chapter 5/Chapter 5.csproj | 4 ++++ Chapter 5/Form1.Designer.cs | 22 +++++++++++++++++++++- Chapter 5/Form1.cs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Chapter 5/Chapter 5.csproj b/Chapter 5/Chapter 5.csproj index 8d85116..b650d3e 100644 --- a/Chapter 5/Chapter 5.csproj +++ b/Chapter 5/Chapter 5.csproj @@ -33,6 +33,7 @@ 4 + @@ -54,6 +55,9 @@ + + Form1.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/Chapter 5/Form1.Designer.cs b/Chapter 5/Form1.Designer.cs index 1270c18..f1914ab 100644 --- a/Chapter 5/Form1.Designer.cs +++ b/Chapter 5/Form1.Designer.cs @@ -29,12 +29,32 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.btnInput = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // btnInput + // + this.btnInput.Location = new System.Drawing.Point(648, 380); + this.btnInput.Name = "btnInput"; + this.btnInput.Size = new System.Drawing.Size(75, 23); + this.btnInput.TabIndex = 0; + this.btnInput.Text = "input"; + this.btnInput.UseVisualStyleBackColor = true; + this.btnInput.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.btnInput); + this.Name = "Form1"; this.Text = "Form1"; + this.ResumeLayout(false); } + private System.Windows.Forms.Button btnInput; + #endregion } } \ No newline at end of file diff --git a/Chapter 5/Form1.cs b/Chapter 5/Form1.cs index 6b72480..cf21753 100644 --- a/Chapter 5/Form1.cs +++ b/Chapter 5/Form1.cs @@ -6,15 +6,45 @@ using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms;using System; +using System.Collections.Generic; using System.Windows.Forms; + namespace Chapter_5 { public partial class Form1 : Form { + public Form1() { InitializeComponent(); } + private List friendNames = new List(); + + private void button1_Click(object sender, EventArgs e) + { + string input = ""; + do + { + input = Microsoft.VisualBasic.Interaction.InputBox( + "Please enter a friend's name, then press ENTER" + Environment.NewLine + "(Enter -99 to stop input)", + "Input", "John Doe", 100, 100); + + if(input != "-99") + { + friendNames.Add(input); + } + } + while (input != "-99"); + + ShowFriendNames(); + } + + private void ShowFriendNames() + { + string names = string.Join(Environment.NewLine, friendNames); + MessageBox.Show("Here are your friends:" + Environment.NewLine + names, "Friends List", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } \ No newline at end of file