1。不同的 control 处理相同的事件
可能会有这样的情况:用户点一个按钮和一个菜单项完成相同的作用(比如都是打开一个文件),这时如果分别写按钮和菜单项的事件处理代码(两端代码完全一样),就会出现重复,而且改动的时候也不得不改动多处。
解决方法:把事件处理代码写成一个单独的方法,比如 OpenFile(),然后在事件处理方法中调用这个独立的方法。
2。ListBox
如何把自定义的类显示在一个 ListBox 中?
答案:override 类的 ToString() 方法(这个方法在 Object 中就存在),然后 ListBox 类的 Add() 方法会自动调用类的 ToString()~~~~
3。ListView 和 TreeView
4。DataGrid
只要设置一下 DataSource 属性就可以了~~
5。List Item Selection
注意:List controls support either custom types or the Tag property but not both. However, a simple wrapper will allow you to add a tag to a list item of any type: