프로그램/C# - Study / / 2010. 9. 17. 12:56

10D - Ex18WindowsForms2

반응형

윈폼으로 만들어서 코딩
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Ex18WindowsForms2
{
    class TheForm : Form
    {
    //    Button btn = new Button();

        private Button btn;
        public TheForm()
        {
            InitializeComponent();
        }

 

        public void InitializeComponent()
        {
            Text = "Hello, Windows Forms";
            Width = 600;
            Height = 500;
            BackColor = Color.Gold;

            btn = new Button();
            btn.Width = 300;
            btn.Height = 100;
            btn.BackColor = Color.Lime;
            btn.Text = "Please Click Me";
            btn.Font = new Font("휴먼엑스포", 20);
            Rectangle rect = ClientRectangle;
            int x = (rect.Width - btn.Width) / 2;
            int y = (rect.Width - btn.Width) / 2;
            btn.Location = new Point(x, y);

            btn.Click += Button_Click;
            this.Controls.Add(btn);
        }
        public void Button_Click(object sender, EventArgs e)
        {
            Random r = new Random();
            BackColor = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256));
        }
    }
}


반응형

'프로그램 > C# - Study' 카테고리의 다른 글

10D - 윈폼  (0) 2010.09.17
10D - Ex19WindowsForms3  (0) 2010.09.17
9D - 윈도우폼 만들기  (0) 2010.09.17
9D - Ex16OOP7 - Interface  (0) 2010.09.16
수업자료  (0) 2010.09.16
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유