winform 实现选择城市列表
标签:winform 控件
先上图
#region 选择城市
///
/// 点击字母事件
///
///
///
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);
}
///
/// 绘制城市控件
///
private void CreatCheckCityControl(string lettey)
{
if (lettey == string.Empty)
{
List list = dicList["RM"];
CreatControl(list);
}
else
{
for (int i = 0; i list = dicList[temp];
CreatControl(list);
}
}
}
private void CreatControl(List 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);
}
}
///
/// 隐藏控件
///
///
///
void FlyReserveForm_MouseUp(object sender, MouseEventArgs e)
{
if (!pan_City.Capture)
{
this.pan_City.Visible = false;
}
if (!calendar.Capture)
{
this.calendar.Hide();
}
}
///
/// 点击选择目的地
///
///
///
void btnToCity_Click(object sender, EventArgs e)
{
sType = 1;
pan_City.Visible = true;
pan_City.Location = new Point(446, 100);
}
///
/// 点击选择出发城市
///
///
///
void btnFromCity_Click(object sender, EventArgs e)
{
sType = 0;
pan_City.Visible = true;
pan_City.Location = new Point(133, 100);
}
///
/// 从xml获取城市列表
///
private void LoadCityArray()
{
List list = new List();
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
winform 实现选择城市列表,搜素材,soscw.com
winform 实现选择城市列表
标签:winform 控件
原文地址:http://blog.csdn.net/mrtraum/article/details/32727823
评论