winform 實現選擇城市列表

來源:互聯網
上載者:User

標籤: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


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.