一、MessageBox的Buttons
MessageBox.Show可以出現有按鈕的對話框
例如:
DialogResult dr = MessageBox.Show("是否要繼續嗎?", "警告!!!", MessageBoxButtons.OKCancel);//它彈出的對話框如下圖所示
if (dr == DialogResult.OK)//只有按下確定按鈕才執行下面
{
label1.Text = "天氣不錯";
}
除此之外MessageBoxButtons還有好幾種對話框
二、三級聯動
三個Combobox
public Form1()// Form1的構造函數
{
InitializeComponent();
AreaDataBind(comboBox1, "0001");
AreaDataBind(comboBox2, comboBox1.SelectedValue.ToString());
AreaDataBind(comboBox3, comboBox2.SelectedValue.ToString());
}
public void AreaDataBind(ComboBox cb, string Pcode)
{
cb.DataSource = new ChinaData().Select(Pcode);//數據源
cb.DisplayMember = "AreaName";//顯示值
cb.ValueMember = "AreaCode";//實際值
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
AreaDataBind(comboBox2, comboBox1.SelectedValue.ToString());
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
AreaDataBind(comboBox3, comboBox2.SelectedValue.ToString());
}
DateTime類型比較大小:
DateTime.Compare(t1,t2)比較兩個日期大小,排前面的小,排在後面的大,比如:2011-2-1就小於2012-3-2