zoukankan      html  css  js  c++  java
  • 窗体Test1

    我在做东西的时候遇到了一个问题,就是说当点击不同的省份时会在panel里面显示相对应的内容,这样写感觉还可以。就做个备份。

    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 Test1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            string[] str = {"郑州","信阳","商丘","洛阳","开封" };
            string[] str1 = { "常州","南京","苏州","无锡","泰安"};
            private void button1_Click(object sender, EventArgs e)
            {
             
            }
            private void radioButton1_CheckedChanged(object sender, EventArgs e)
            {
                //拆箱,在一个事件里面拆箱控件
                RadioButton rb = (RadioButton)sender;
                //if (rb.Checked)
                //{
                //    MessageBox.Show(rb.Text);
                //}
                //判断按钮的TEXT,应该还有别的好的方法,可惜没找到
                if (rb.Text == "河南省")
                {
                    //调用函数
                    BangDing(str);
                }
                else if(rb.Text=="江苏省")
                {
                    BangDing(str1);
                }
                //弹出提示框
              if(rb.Checked)
              {
                  MessageBox.Show(rb.Text);
              }
            }

            private void Form1_Load(object sender, EventArgs e)
            {

             
              
              
            }
            /// <summary>
            /// 添加单选按钮控件
            /// </summary>
            /// <param name="stra"> 数组名,参数</param>
           public void BangDing(string[] stra)
            {
                panel2.Controls.Clear();
               
                for (int i = 0; i < 5; i++)
                {
                   
                    RadioButton rb = new RadioButton();
                    //为新加的控件添加 调用事件,并绑定方法
                    rb.CheckedChanged += new EventHandler(radioButton1_CheckedChanged);
                    rb.Name = rb + (i + 1).ToString();
                    rb.Text = stra[i].ToString();
                    rb.Location = new Point(0, 22 * i);
                    panel2.Controls.Add(rb);
                }
            }

        
        }
    }

  • 相关阅读:
    python 线程Queue 用法代码展示
    Python中的join()函数的用法
    python 中爬虫 content和text的区别
    免费代理ip爬虫分享
    django数据库的表已迁移的不能重新迁移的解决办法
    RuntimeError: Model class app_anme.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.---python学习错误记录
    MYSQL查询操作 详细
    mysql数据库的基本操作命令总结
    http短连接与长连接简介
    浅谈http协议
  • 原文地址:https://www.cnblogs.com/wyj1990/p/2181472.html
Copyright © 2011-2022 走看看