码迷,mamicode.com
首页 > Windows程序 > 详细

C#自学之路33

时间:2015-04-14 23:33:39      阅读:400      评论:0      收藏:0      [点我收藏+]

标签:private   public   对话框   用户   

33.模态对话框

  所谓模态对话框,就是指当有个对话框弹出的时候,用户必须在对话框中做出响应的操作,在退出对话框之前,鼠标不能单击对话框以外的位置。


   

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;


namespace WindowsFormsApplication23

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            Form2 form2 = new Form2();

            form2.n_text = this.Text;

            form2.n_color = this.BackColor;


            form2.ShowDialog();


            if ( form2.DialogResult == DialogResult.OK )

            {

                this.Text = form2.n_text;

                this.BackColor = form2.n_color;

            }

        }

    }

}


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;


namespace WindowsFormsApplication23

{

    public partial class Form2 : Form

    {

        private Color color;

        private string text;


        public Form2()

        {

            InitializeComponent();

        }


        public Color n_color

        {

            get

            {

                return color;

            }

            set

            {

                this.color = value;

                radioButton1.Checked = false;

                radioButton2.Checked = false;

                radioButton3.Checked = false;


                if ( color == Color.Red )

                    radioButton1.Checked = true;

                if ( color == Color.Yellow )

                    radioButton2.Checked = true;

                if ( color == Color.Blue )

                    radioButton3.Checked = true;


            }

        }


        public string n_text

        {

            get

            {

                return text;

            }

            set

            {

                this.text = value;

                textBox1.Text = text;

            }

        }


        private void radioButton1_CheckedChanged(object sender, EventArgs e)

        {

            if ( radioButton1.Checked )

                color = Color.Red;

        }


        private void radioButton2_CheckedChanged(object sender, EventArgs e)

        {

            if ( radioButton2.Checked )

                color = Color.Yellow;

        }


        private void radioButton3_CheckedChanged(object sender, EventArgs e)

        {

            if (radioButton3.Checked)

                color = Color.Blue;

        }


        private void textBox1_TextChanged(object sender, EventArgs e)

        {

            text = textBox1.Text;

        } 

    }

}






技术分享

本文出自 “郭俊的博客” 博客,转载请与作者联系!

C#自学之路33

标签:private   public   对话框   用户   

原文地址:http://10093949.blog.51cto.com/10083949/1632409

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!