• winform 实现选择的城市名单


    首先在地图上


     #region 选择城市
            /// <summary>
            /// 点击字母事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void item_Click(object sender, EventArgs e)
            {
                LinkLabel lbl = sender as LinkLabel;
                lbl.Font = new Font(new FontFamily("宋体"), 10, FontStyle.Bold);
                foreach (Control item in pan_CityTitle.Controls)
                {
                    if (item is LinkLabel && item != lbl)
                        item.Font = new Font(new FontFamily("宋体"), 10, FontStyle.Regular);
                }
                flowLayoutPanel.Controls.Clear();
                CreatCheckCityControl(lbl.Tag != null ? lbl.Tag.ToString() : string.Empty);
            }
           
            /// <summary>
            /// 绘制城市控件
            /// </summary>
            private void CreatCheckCityControl(string lettey)
            {
                if (lettey == string.Empty)
                {
                    List<FlyCity> list = dicList["RM"];
                    CreatControl(list);
                }
                else
                {
                    for (int i = 0; i < lettey.Length; i++)
                    {
                        string temp = lettey.Substring(i, 1);
                        if (!dicList.Keys.Contains(temp))
                        {
                            continue;
                        }
                        List<FlyCity> list = dicList[temp];
                        CreatControl(list);
                    }
                }
            }
            private void CreatControl(List<FlyCity> list)
            {
                foreach (FlyCity fly in list)
                {
                    Button button = new Button()
                    {
                        Text = fly.CityName,
                        Tag = fly,
                        Width = 76,
                        Height = 25,
                        ForeColor = Color.FromArgb(89, 89, 89),
                        FlatStyle = FlatStyle.Flat,
                    };
                    button.FlatAppearance.BorderColor = Color.White;
                    button.Click += new EventHandler(button_Click);
                    button.MouseHover += new EventHandler(button_MouseHover);
                    button.MouseLeave += new EventHandler(button_MouseLeave);
                    flowLayoutPanel.Controls.Add(button);
                }
            }
            /// <summary>
            /// 隐藏控件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void FlyReserveForm_MouseUp(object sender, MouseEventArgs e)
            {
                if (!pan_City.Capture)
                {
                    this.pan_City.Visible = false;
                }
                if (!calendar.Capture)
                {
                    this.calendar.Hide();
                }
            }
            /// <summary>
            /// 点击选择目的地
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void btnToCity_Click(object sender, EventArgs e)
            {
                sType = 1;
                pan_City.Visible = true;
                pan_City.Location = new Point(446, 100);
            }
            /// <summary>
            /// 点击选择出发城市
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void btnFromCity_Click(object sender, EventArgs e)
            {
                sType = 0;
                pan_City.Visible = true;
                pan_City.Location = new Point(133, 100);
            }
            /// <summary>
            /// 从xml获取城市列表
            /// </summary>
            private void LoadCityArray()
            {
                List<FlyCity> list = new List<FlyCity>();
                XmlHelper help = new XmlHelper(Environment.CurrentDirectory + "\arrays.xml");
                DataSet ds = help.GetData("resources");
                foreach (DataRow item in ds.Tables[0].Rows)
                {
                    FlyCity fly = new FlyCity();
                    string city = item[0].ToString().Substring(0, item[0].ToString().IndexOf(","));
                    string cityCode = item[0].ToString().Substring(item[0].ToString().IndexOf(",") + 1, item[0].ToString().Length - item[0].ToString().IndexOf(",") -1);
                    fly.CityName = city;
                    fly.CityCode = cityCode;
                    list.Add(fly);
                }
                dicList = ChineseConvert.InsertDic(list);
            }
            
    
            void button_Click(object sender, EventArgs e)
            {
                if ((sender as Button).Tag == null)
                    return;
                FlyCity fly = (sender as Button).Tag as FlyCity;
                if (sType == 0)
                {
                    lblFromCity.Text = fly.CityName;
                    lblFromCity.Tag = fly;
                }
                else
                {
                    lblToCity.Text = fly.CityName;
                    lblToCity.Tag = fly;
                }
                pan_City.Visible = false;
            }
            
            private void Pan_TitleClick()
            {
                foreach (Control item in pan_CityTitle.Controls)
                {
                    if(item is LinkLabel)
                        item.Click += new EventHandler(item_Click);
                }
            }
    
            
            void button_MouseLeave(object sender, EventArgs e)
            {
                (sender as Button).BackColor = Color.White;
                (sender as Button).ForeColor = Color.FromArgb(89, 89, 89);
            }
    
            void button_MouseHover(object sender, EventArgs e)
            {
                (sender as Button).BackColor = Color.FromArgb(41, 100, 180);
                (sender as Button).ForeColor = Color.White;
            }
            #endregion


    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    pthread_once函数的简单示例
    pthread_join直接决定资源是否能够及时释放
    非分离线程未使用join函数例子:
    一个HTTP打趴80%面试者
    BM和KMP字符串匹配算法学习
    STL 几个容器的底层实现
    指针的引用(*&)与指针的指针(**)
    Maven 环境变量设置
    配置JAVA的环境变量
    Maven报错 解决方案。ERROR: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4855349.html
Copyright © 2020-2023  润新知