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);
                }
            }

        
        }
    }

  • 相关阅读:
    树形结构菜单,递归实现
    基于Vue的日历组件,可以标注重要日子
    关于element-ui级联菜单(城市三级联动菜单)和回显问题
    继承(面试问到)
    vue监听浏览器刷新
    Popover 弹出框,里面的表格点击后关闭弹窗
    el-table表格合并单元格
    对角线
    ElementUI中el-radio再次点击取消选中
    保留文本框换行和空格
  • 原文地址:https://www.cnblogs.com/wyj1990/p/2181472.html
Copyright © 2011-2022 走看看