Ch5 try it

This commit is contained in:
EggMan20339 2024-02-05 22:30:11 -05:00
parent 885a8f55f4
commit 731c9279e4
3 changed files with 55 additions and 1 deletions

View File

@ -33,6 +33,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System"/> <Reference Include="System"/>
<Reference Include="System.Core"/> <Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/> <Reference Include="System.Xml.Linq"/>
@ -54,6 +55,9 @@
</Compile> </Compile>
<Compile Include="Program.cs"/> <Compile Include="Program.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/> <Compile Include="Properties\AssemblyInfo.cs"/>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>

View File

@ -29,12 +29,32 @@
/// </summary> /// </summary>
private void InitializeComponent() 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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.btnInput);
this.Name = "Form1";
this.Text = "Form1"; this.Text = "Form1";
this.ResumeLayout(false);
} }
private System.Windows.Forms.Button btnInput;
#endregion #endregion
} }
} }

View File

@ -6,15 +6,45 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;using System;
using System.Collections.Generic;
using System.Windows.Forms; using System.Windows.Forms;
namespace Chapter_5 namespace Chapter_5
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
} }
private List<string> friendNames = new List<string>();
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);
}
} }
} }