728x90
반응형

[예제1]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

//ProgressBar TrackBar
// TreeView
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        Random random = new Random(100);
        public Form1()
        {
            InitializeComponent();

            listView1.BeginUpdate();

            listView1.View = View.Details;
            listView1.Columns.Add("이름", 200, HorizontalAlignment.Left); // 컬럼의 크기 200
            listView1.Columns.Add("나이", 200, HorizontalAlignment.Right);
            listView1.Columns.Add("급여", 200, HorizontalAlignment.Center);

            listView1.EndUpdate();

            // 방법1
            string[] data = new string[] { "호랑이1", "코끼리", "독수리" };
            ListViewItem lv = new ListViewItem(data);
            listView1.Items.Add(lv);

            // 방법2
            lv = new ListViewItem(
                new string[] { "호랑이2", "코끼리", "독수리" }
                );
            listView1.Items.Add(lv);

            // 방법3
            lv = new ListViewItem("호랑이3");
            lv.SubItems.Add("코끼리");
            lv.SubItems.Add("독수리");
            listView1.Items.Add(lv);

            // 방법4
            listView1.Items.Add(new ListViewItem(
                new string[] { "호랑이4", "코끼리", "독수리;" }
                ));                       
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string name = "호랑이" + random.Next();
            listView1.Items.Add(new ListViewItem(
                new string[] {name, "코끼리", "독수리"}
                ));
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // MessageBox.Show("Form1_Load");
            var Fonts = FontFamily.Families;
            foreach(FontFamily item in Fonts)
            {
                comboBox1.Items.Add(item);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //MessageBox.Show("콤보 클릭");
            ChangeFont();
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            ChangeFont();
        }
        void ChangeFont()
        {
            if (comboBox1.SelectedIndex < 0)
            {
                return;
            }

            // 폰트 스타일의 객체 초기화
            FontStyle style = FontStyle.Regular;
            if(checkBox1.Checked)
            {
                style |= FontStyle.Bold;
            }

            if (checkBox2.Checked)
            {
                style |= FontStyle.Italic;
            }

            textBox1.Font = new Font(
                (FontFamily)comboBox1.SelectedItem, 10, style);
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show("1", "2", MessageBoxButtons.OKCancel);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form form = new Form();
            form.Text = "모달 폼";
            form.Width = 300;
            form.Height = 100;
            form.BackColor = Color.Red;
            form.ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form form = new Form();
            form.Text = "모달리스 폼";
            form.Width = 300;
            form.Height = 300;
            form.BackColor = Color.Green;
            form.Show();
        }

        
    }
}

728x90
반응형

'Education > Edu | .net' 카테고리의 다른 글

# 34) [WPF] 기본다지기1  (0) 2021.03.04
# 33) [C#] Winform 3 (VS2017에서 Oracle11g로 데이터 연동)  (0) 2021.03.03
# 31) [C#] Winform 1  (0) 2021.02.26
# 30) [C#] 문법13 (thread)  (0) 2021.02.26
# 29.2) [C#] 문법12  (0) 2021.02.24

+ Recent posts