Labelのサイズを自由に変更する
デフォルトではラベルのサイズは自由に変更できませんので、
にすることで、自由に変更できます。
DateTimePicker(カレンダー)関連
string strDate = "2012/12/12";dateTimePicker1.Text = strDate;//こういう方法もありdateTimePicker1.Value = new DateTime(2001, 10, 20);
現在の日付を取得する(DateTimeクラス)
DateTime dtToday = DateTime.Today;時間の計算(TimeSpanクラス)
//startTimeとendTimeはそれぞれDateTimeクラスTimeSpan tSpan = endTime-startTime;コンボボックス
値の追加
comboBox1.Items.Add("山田");comboBox1.Items.Add("田中");値の参照
string txt = comboBox1.SelectedItem.ToString();クラスを用いて値を追加 推奨
各項目に関する情報を管理するデータクラスを作る
public class MyComboBoxItem { private string _id = ""; private string _name = ""; //コンストラクタ public MyComboBoxItem(string id, string name) { _id = id; _name = name; } public string Id { get { return _id; } } public string Name { get { return _name; } } public override string ToString(){ return _name; } }
データクラスを格納する
MyComboBoxItem item; item = new MyComboBoxItem("001", "山田"); comboFruit.Items.Add(item); item = new MyComboBoxItem("002", "田中"); comboFruit.Items.Add(item);リストボックス
選択されている項目
string result = ListBox1.SelectedItems[i]);
複数選択の場合
Console.WriteLine("選択されているすべての項目:");
for (int i = 0; i < ListBox1.SelectedItems.Count; i++) { string result = ListBox1.SelectedItems[i]); }