반응형
using System;
using System.Collections;
using System.Windows.Forms;
public class MyForm : Form{
LanguageSelector combo;
public MyForm(){
combo = new LanguageSelector();
combo.Location = new System.Drawing.Point(10,10);
this.Controls.Add(combo);
combo.SelectedValue = 2;
}
public static void Main(string[] args){
Application.Run(new MyForm());
}
}
public class KVPair{
private int myKey;
private string myValue;
public KVPair(string Value, int Key){
this.myValue = Value;
this.myKey = Key;
}
public string Value{
get{
return myValue;
}
set{
myValue = value;
}
}
public int Key{
get{
return myKey;
}
set{
myKey = value;
}
}
}
public class LanguageSelector : ComboBox{
ArrayList languages;
public LanguageSelector(){
languages = new ArrayList();
languages.Add(new KVPair("Unknown",0));
languages.Add(new KVPair("Dutch Flemish",1));
languages.Add(new KVPair("English",2));
languages.Add(new KVPair("French",3));
languages.Add(new KVPair("German",4));
languages.Add(new KVPair("Italian",5));
languages.Add(new KVPair("Portuguese",6));
languages.Add(new KVPair("Spanish",7));
languages.Add(new KVPair("Other",8));
this.DataSource = languages;
this.DisplayMember = "Value";
this.ValueMember = "Key";
}
}
using System.Collections;
using System.Windows.Forms;
public class MyForm : Form{
LanguageSelector combo;
public MyForm(){
combo = new LanguageSelector();
combo.Location = new System.Drawing.Point(10,10
this.Controls.Add(combo);
combo.SelectedValue = 2;
}
public static void Main(string[] args){
Application.Run(new MyForm());
}
}
public class KVPair{
private int myKey;
private string myValue;
public KVPair(string Value, int Key){
this.myValue = Value;
this.myKey = Key;
}
public string Value{
get{
return myValue;
}
set{
myValue = value;
}
}
public int Key{
get{
return myKey;
}
set{
myKey = value;
}
}
}
public class LanguageSelector : ComboBox{
ArrayList languages;
public LanguageSelector(){
languages = new ArrayList();
languages.Add(new KVPair("Unknown",0));
languages.Add(new KVPair("Dutch Flemish",1));
languages.Add(new KVPair("English",2));
languages.Add(new KVPair("French",3));
languages.Add(new KVPair("German",4));
languages.Add(new KVPair("Italian",5));
languages.Add(new KVPair("Portuguese",6));
languages.Add(new KVPair("Spanish",7));
languages.Add(new KVPair("Other",8));
this.DataSource = languages;
this.DisplayMember = "Value";
this.ValueMember = "Key";
}
}
반응형