C#学习之四---ListBox
来源:互联网 发布:长沙智工软件 编辑:程序博客网 时间:2024/05/18 13:48
呵呵 没想到在C#中做ListBox这么简单,不多说了,马上写出我今天实践做的ListBox.
建设WPF工程我就不重复了,直接将ListBox,
在工具箱中调出ListBox控件,选中它,F4,调出其对应的属性,将其名称改为myList;
在属性中找到下图 Ttems ,点击后面的3点框。
会弹出一个对话框,我们关心的是我们对话框的左下方,如下图:
选择ListBoxItem;
添加6个ListBoxItem,如图:
在每个ListBoxItem的属性中将Content改为对应的myList1---myList6,还可以根据自己的爱好改变对应的颜色;
最后我们的应用程序做出来了,如图:
额 ListBox没有左侧的下来条啊,不好看.
呵呵 为了可以见到下来条,我们把ListBox缩小,如图:
这样我们就可以看到下拉条了,
最后的成果图:
为了可以实现ListBox的选择作用:
我们加入代码,关键部分的如下:
ListBoxItem selectedList = (myList.SelectedItem as ListBoxItem );这代码就是读取对应的选择List.
这段代码和上一段是等效的:
ListBoxItem selectedlist = (ListBoxItem)myList.SelectedItem;
最后整体代码如下,用的是switch语句;
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace myList{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void ListBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { ListBoxItem selectedList = (myList.SelectedItem as ListBoxItem ); switch (selectedList.Content.ToString()) { case "myList1": showMyList1(); break; case "myList2": showMyList2(); break; case "myList3": showMyList3(); break; case "myList4": showMyList4(); break; case "myList5": showMyList5(); break; case "myList6": showMyList6(); break; default : showMyList(); break; } } private void showMyList1() { textName.Text ="myList1"; } private void showMyList2() { textName.Text = "myList2"; } private void showMyList3() { textName.Text = "myList3"; } private void showMyList4() { textName.Text = "myList4"; } private void showMyList5() { textName.Text = "myList5"; } private void showMyList6() { textName.Text = "myList6"; } private void showMyList() { textName.Text = "Wrong List!"; } }}
最后是应用程序的效果图:
我们下拉下拉条,选择myList6,空白框显示了我们选择的myList6,
这就是我们今天的ListBox实践,
OVER!!!
- C#学习之四---ListBox
- C#窗体控件之listbox
- C#学习教程之四
- c#学习笔记2(listbox的应用)
- C# Winform编程ListBox之添加图标
- C# Winform编程ListBox之添加图标
- C#学习之控件:listbox显示多条数据以及周边操作
- C#学习笔记之四:接口
- Tkinter学习笔记之Listbox列表
- C#界面设计之ComboBox与ListBox的使用
- C#之winform基础 listbox控件可以多选
- C#之winform基础 为listbox添加右键菜单
- C#学习笔记四
- C#学习笔记(四)
- C#学习笔记(四)
- C#学习笔记(四)
- C#学习笔记之四(Attribute, Reflection, Thread, Thread Syn
- 学习C#操纵Visio之四:设置Shape颜色
- jquery的ajax()函数传值中文乱码的解决方案
- iOS 关于音频开发
- UVaOJ 10361 - Automatic Poetry
- 较为简单的一种判断Retina屏幕的方法
- Extjs自定义组件
- C#学习之四---ListBox
- 一个牛人给java初学者的建议
- poj 1903 zoj 2469 la2965(live archive) 中途相遇法
- 编写一个方法,输出在一个字符串中,指定字符串出现的次数
- C#事件(event)解析(转)
- smarty保留变量
- hdu 3549 Flow Problem 最大流入门 EK算法
- WEB水晶报表直接打印 ---设置
- GCC-C语言编辑器