본문 바로가기
C#

라벨 이용하기

by improve 2024. 2. 16.

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#' 카테고리의 다른 글

c# 수업중 내용  (0) 2024.02.19
원 처럼 움직이기  (0) 2024.02.19
C# 콘솔  (0) 2024.02.13
c# oracle에서 연동, listbox에 보여주기.  (0) 2024.02.08
계산기  (0) 2024.02.08