namespace WinFormsApp100
{
public partial class Form1 : Form
{
int y = 10;
class Car
{
public String Name { get; set; }
}
List<Car> list = new List<Car>();
public Form1()
{
InitializeComponent();
//MakeLabel(10, 90, "추가됨");
Car car1 = new Car() { Name = "마이자동차" };
Car car2 = new Car() { Name = "마이2자동차" };
list.Add(car1);
list.Add(car2);
foreach (Car car in list)
{
Console.WriteLine(car);
MakeLabel(10, y, car.Name);
y += 40;
}
}
public void MakeLabel(int x, int y, String text)
{
label1 = new Label();
label1.AutoSize = true;
label1.Location = new Point(x, y);
label1.Size = new Size(39, 15);
label1.TabIndex = 0;
label1.Text = text;
Controls.Add(label1);
}
private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine(textBox1.Text);
MakeLabel(10, y = y + 40, textBox1.Text);
textBox1.Text = "";
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1_Click(null, null);
}
}
}
}
버튼을 눌럿을때 나 엔터키를 눌렀을때 입력이 된다.
C#