begincsdn .NET 趴趴窝
[天行健,君子以自强不息]
[天道酬勤思]
我们常看到VS.net中可以将一些枚举型的值放到下拉框中显示,就不禁自问:如何实现的?

 1using System;
 2
 3public class GetNamesTest 
 4{
 5    enum Colors 
 6    
 7      Red, Green, Blue, Yellow 
 8    }
;
 9    enum Styles 
10    
11      Plaid, Striped, Tartan, Corduroy 
12    }
;
13
14    public static void Main() 
15    {
16        Console.WriteLine("The values of the Colors Enum are:");
17        foreach(string s in Enum.GetNames(typeof(Colors)))
18            Console.WriteLine(s);
19        Console.WriteLine();
20        Console.WriteLine("The values of the Styles Enum are:");
21        foreach(string s in Enum.GetNames(typeof(Styles)))
22            Console.WriteLine(s);
23    }

24


那么加到下拉框也就很简单了。
1string [] names = Enum.GetNames(typeof(DockStyle));
2comboBox1.Items.Clear();
3foreach(string name in names)
4{
5this.comboBox1.Items.Add(name);
6}

posted on 2005-07-12 21:29  begincsdn  阅读(791)  评论(0编辑  收藏  举报