只能輸入數字和小數﹕(keypKeyPress事件中調用)
if((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 46 && e.KeyChar != 8 && e.KeyChar != 13)
例子1﹕
private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 46 && e.KeyChar != 8 && e.KeyChar != 13)
this.textBox2.Enabled=false;
}
例子2﹕
private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar)) e.Handled = true;
this.textBox2.Enabled=false;
}
獲取本機IP地址﹕this.textBox1.Text = Dns.Resolve( Dns.GetHostName() ).AddressList[0].ToString();
鼠標懸停時顯示提示文字
private void button1_Click(object sender, System.EventArgs e)
{
ToolTip ttTemp = new ToolTip();
ttTemp.AutoPopDelay = 5000;
ttTemp.AutomaticDelay = 500;
ttTemp.InitialDelay = 100;
ttTemp.SetToolTip(this.button1, this.button1.Text||'123456');
}