본문 바로가기

   
Programming/Winform

윈폼(winform) 이벤트, 상속 버튼 생성, 데이트타입 이용 예제

반응형

윈폼(winform) 이벤트, 상속 버튼 생성, 데이트타입 이용 예제

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Collections;

 

namespace WindowsForms01

{

       public partial class Study01 : Form

       {

             private int a;

             private int b;

             private int c;

             private int d;

             private int f;

 

             public Study01()

             {

                    InitializeComponent();

                    a = 10;

                    b = 10;

                    c = 100;

                    d = 10;

                    f = 0;

             }

 

             private void button1_Click(object sender, EventArgs e)

             {

                    Button btn = new Button();

                    Control.ControlCollection cc = this.Controls;

                    btn.Location = new Point(a, b);

                    btn.Text = string.Format("떠라좀{0}", f);                  

                    btn.Click += new EventHandler(btn_Click);

                    this.f += 1;

 

                    if (this.panel1.Controls.Count < 8)

                    {

                           this.Controls.Add(btn);

                           this.panel1.Controls.Add(btn);

                           this.b += 30;

                    }

                    else if (this.panel1.Controls.Count < 16)

                    {

                           btn.Location = new Point(c, d);

                           this.Controls.Add(btn);

                           this.panel1.Controls.Add(btn);

                           //this.c += 20;

                           this.d += 30;

                    }

 

                    else

                    {

                           MessageBox.Show("그만넣어");

                    }

             }

 

             void btn_Click(object sender, EventArgs e)

             {

                   

             }

 

             private void button2_Click(object sender, EventArgs e)

             {

                    if (this.panel1.Controls.Count > 0)

                    {

                           this.panel1.Controls.RemoveAt(0);

                    }

                    else

                    {

                           MessageBox.Show("스톱");

                    }

                   

             }

       }

}






using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace WindowsForms01

{

       public partial class Study02_good : Form

       {

             private int count;

             private DateTime start, end;

 

             public Study02_good()

             {

                    InitializeComponent();

                    count = 0;

             }

 

             private void button2_Click(object sender, EventArgs e)

             {

                    Move();

                    button2.Hide();

                    this.start = DateTime.Now;//시계를 보고 기억

                    MessageBox.Show(start.ToString());

             }

 

             private void button1_Click(object sender, EventArgs e)

             {

                    Move();

             }

 

 

             private void Move()

             {

                    //어디론가 배치 -> 난수

                    Random rnd = new Random();

                    //x 0~해상도의 너비

                    //y 0~해상도의 너비

                    int x = rnd.Next(SystemInformation.WorkingArea.Width - this.Width);

                    int y = rnd.Next(SystemInformation.WorkingArea.Height - this.Height);

 

                    this.Location = new Point(x, y);

 

                    count++;//클릭한 횟수

 

                    if (count == 11)

                    {

                           //게임끝나는 시간

                           this.end = DateTime.Now;

                           TimeSpan result = start - end;

                           MessageBox.Show(String.Format("총 소요시간 : {0:N0}", result.TotalSeconds));

 

                           //초기화

                           //1. 감춘 버튼을 다시 보이게.. 시작

                           this.button2.Show();

                           this.button1.Text = "";

                           this.count = 0;

                    }

                    else

                    {

                           //게임중

                           this.button1.Text = count.ToString();

                    }

             }

 

            

       }

}



  마우스 십자선 움직이기
  자리배치
  커튼
  달력
  시계

차단된 친구 허용된 친구 구현 예제


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace WindowsFormsEx

{

       public partial class Ex44_ListBox : Form

       {

             public Ex44_ListBox()

             {

                    InitializeComponent();

             }

 

             private void Ex44_ListBox_Load(object sender, EventArgs e)

             {

                    //기본 목록 추가

                    listBoxDeny.Items.Add("아이유");

                    listBoxDeny.Items.Add("이수민");

                    listBoxDeny.Items.Add("씨스타");

                    listBoxDeny.Items.Add("루피");

                    listBoxDeny.Items.Add("조로");

                    listBoxDeny.Items.Add("설현");

                    listBoxDeny.Items.Add("유진");

                    listBoxDeny.Items.Add("홍길동");

                    listBoxDeny.Items.Add("이무기");

                    listBoxDeny.Items.Add("아무개");

             }

 

             private void buttonAdd_Click(object sender, EventArgs e)

             {

                    AddName();

             }

 

             private void AddName()

             {

                    if (textBoxName.Text.Trim() != string.Empty)

                    {

                           listBoxDeny.Items.Add(textBoxName.Text);

                           textBoxName.Text = string.Empty;

                           textBoxName.Focus();

                    }

             }

 

             private void textBoxName_KeyDown(object sender, KeyEventArgs e)

             {

                    if (e.KeyCode == Keys.Enter)

                    {

                           AddName();

                    }

             }

 

             private void buttonAllow_Click(object sender, EventArgs e)

             {

                    MoveOne(listBoxDeny, listBoxAllow);

             }

 

             private void MoveOne(ListBox listBoxStart, ListBox listBoxEnd)

             {

                    if (listBoxStart.SelectedIndex > -1)

                    {

                           listBoxEnd.Items.Add(listBoxStart.SelectedItem.ToString());

                           listBoxStart.Items.RemoveAt(listBoxStart.SelectedIndex);

                    }

                    else

                    {

                           MessageBox.Show("선택하세요!!");

                    }

             }

 

             private void buttonDeny_Click(object sender, EventArgs e)

             {

                    MoveOne(listBoxAllow, listBoxDeny);

             }

 

             private void buttonAllowAll_Click(object sender, EventArgs e)

             {

                    MoveAll(listBoxDeny, listBoxAllow);

             }

 

             private void buttonDenyAll_Click(object sender, EventArgs e)

             {

                    MoveAll(listBoxAllow, listBoxDeny);

             }

 

             private void MoveAll(ListBox listBoxStart, ListBox listBoxEnd)

             {

                    for (int i = 0; i < listBoxStart.Items.Count; i++)

                    {

                           listBoxEnd.Items.Add(listBoxStart.Items[i]);

                    }

                    listBoxStart.Items.Clear();

             }

       }

}

 

 

 

반응형