블로그 이미지
따시쿵

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

'multiple windows'에 해당되는 글 1

  1. 2015.01.24 멀티플(multiple) 윈도우 - 1
2015. 1. 24. 10:07 C#

1. 

메인 폼에서 showDialog 를 이용해서 폼 Form2 를 새로 만듭니다.

Form2 창에서 OK, Cancel 버튼을 선택하는 것을 보여 주는 예제입니다.


실행화면




프로그램


1. 메인 창

        private void btnFormTwo_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            if (f2.ShowDialog() == DialogResult.OK)
                MessageBox.Show("OK button clicked");
            else if (f2.ShowDialog() == DialogResult.Cancel)
                MessageBox.Show("Cancel button clicked");
        }


2. Form2

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }


2.

메인 창에서 Form2를 띄웁니다. 메인창에 있는 textbox 를 Form2 에 전달하고, Form2 에서 대문자, 소문자로 변경한 내용을 다시 메인창의 텍스트박스에서 보여지게 합니다.


실행화면






프로그램


1. 메인 창

        public static TextBox tb = new TextBox();
        private void btnChangeCase_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            if (f2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                MessageBox.Show("OK");
            else
                MessageBox.Show("Cancel");
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            tb = txtChangeCase;
        }


2. Form2

using System.Globalization;
using System.Threading;

        private void btnOK_Click(object sender, EventArgs e)
        {
            string changeCase = MainForm.tb.Text;

            if (radioButton1.Checked)
                changeCase = changeCase.ToUpper();
            else if (radioButton2.Checked)
                changeCase = changeCase.ToLower();
            else if (radioButton3.Checked)
            {
                CultureInfo properCase = Thread.CurrentThread.CurrentCulture;
                TextInfo textInfoObject = properCase.TextInfo;

                changeCase = textInfoObject.ToTitleCase(changeCase);
            }

            MainForm.tb.Text = changeCase;

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

posted by 따시쿵
prev 1 next