C#-webBrowser-comboBox

2022-06-28 08:47:56 浏览数 (2)

C#-webBrowser-自制浏览器

控件textBox和按钮,webBrower

点击事件:

代码语言:javascript复制
private void button1_Click(object sender, EventArgs e)
        {
            string text = textBox1.Text;
            Uri uri = new Uri("http://" text);
            webBrowser1.Url = uri;
        }

comboBox关于下拉框选择年月日 难点: 1.只有选中年才能选月只有选中月才能选年。 2.根据年月判断2月有多少天

源碼:

代码语言:javascript复制
		private void Form1_Load(object sender, EventArgs e)
        {
            int year = DateTime.Now.Year;
            for (int i = year; i >= 1949; i--)
            {
                cboYear.Items.Add(i "年");
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //换年份就会清空之前选中的月份
            cboMouth.Items.Clear();
            for (int i = 1; i <= 12; i  )
            {
                cboMouth.Items.Add(i "月");
            }
        }
        /// <summary>
        /// 月份改变的时候加载天
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cboMouth_SelectedIndexChanged(object sender, EventArgs e)
        {
            cboDay.Items.Clear();
            int day = 0;//定义一个变量来存储天数stringSplitions.RemoveEmptyEntries
            //获得月份
            string strMoth=cboMouth.SelectedItem.ToString().Split(new char[]{'月'},StringSplitOptions.RemoveEmptyEntries)[0];
            string strYear = cboYear.SelectedItem.ToString().Split(new char[] { '年' }, StringSplitOptions.RemoveEmptyEntries)[0];
            int moth = Convert.ToInt32(strMoth);
            int year = Convert.ToInt32(strYear);
            switch (moth)
            {
                case 1:
                    day = 31;
                    break;
                case 3:
                    day = 31;
                    break;
                case 5:
                    day = 31;
                    break;
                case 7:
                    day = 31;
                    break;
                case 8:
                    day = 31;
                    break;
                case 10:
                    day = 31;
                    break;
                case 12:day = 31;
                    break;
                case 2:
                    if ((year % 400 == 0)||( year % 4 == 0 && 100 !=0))
                    {
                        day = 29;
                    }
                    else
                    {
                        day = 28;
                    }
                    break;
                default:day = 30;
                    break;
            }
            for (int i = 1; i <= day; i  )
            {
                cboDay.Items.Add(i   "日");
            }
        }

0 人点赞