CSDN论坛 > .NET技术 > C#

现在我的窗体有60个textBox,每个都只能输入数字,那么要写60个private void textBox3_KeyDown(object sender, System.Windows.Forms.Key [问题点数:50分,结帖人65426]

Bbs1
本版专家分:6
结帖率 100%
CSDN今日推荐
Bbs1
本版专家分:53
Bbs10
本版专家分:150126
Blank
进士 2003年 总版技术专家分年内排行榜第六
Blank
铜牌 2003年6月 总版技术专家分月排行榜第三
2002年11月 总版技术专家分月排行榜第三
Blank
微软MVP 2003年9月 荣获微软MVP称号
Blank
红花 2003年6月 .NET技术大版内专家分月排行榜第一
2003年5月 .NET技术大版内专家分月排行榜第一
Bbs4
本版专家分:1441
Bbs7
本版专家分:10544
Blank
红花 2003年2月 VB大版内专家分月排行榜第一
Bbs7
本版专家分:10544
Blank
红花 2003年2月 VB大版内专家分月排行榜第一
Bbs4
本版专家分:1296
Bbs1
本版专家分:0
匿名用户不能发表回复!
其他相关推荐
winform计算器
private void button1_Click(object sender, EventArgs e)//数字 { Button btn = (Button)sender; textBox1.Text += btn.Text; }
dock的应用,控制工具条在窗体中的位置,C#源代码private void toolStripButton1_Click(object
dock的应用,控制工具条在窗体中的位置,C#源代码private void toolStripButton1_Click(object sender, EventArgs e) { //靠上 this.toolStrip1.Dock = DockStyle.Top; } private void toolStripButton2_Click(object sender, EventArgs e) { //靠下 this.toolStrip1.Dock = DockStyle.Bottom; } private void toolStripButton3_Click(object sender, EventArgs e) { //靠左 this.toolStrip1.Dock = DockStyle.Left; } private void toolStripButton4_Click(object sender, EventArgs e) { //靠右 this.toolStrip1.Dock = DockStyle.Right; } VisualStudio2008创建
textbox只能输入数字
textbox只能输入数字,textbox只能输入数字,textbox只能输入数字textbox只能输入数字
C# 设置文本框等控件只能输入 正负整数或小数
//摘要: C# 文本输入控件,通过KeyPress事件实现只能输入正负正数和小数的功能 private void Value_KeyPress(object sender, KeyPressEventArgs e) { var tb = sender as TextBox; if (null ==
c#对话框练习
有关对话框的练习小程序。 private void triangle_Click(object sender, EventArgs e) { triangle nForm=new triangle(); nForm.Show (); } private void square_Click(object sender, EventArgs e) { square nForm = new square(); nForm.Show(); } private void circle_Click(object sender, EventArgs e) { circle nForm = new circle(); nForm.Show(); } private void button4_Click(object sender, EventArgs e) { Application.Exit(); } private void button1_Click(object sender, EventArgs e) { Form1 nForm = new Form1(); nForm.Show(); } } }
Nathan记事本源代码
一个功能比较全面的记事本源代码示例 private void 复制ToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Copy(); } private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Cut(); } private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Paste(); } private void 撤消ToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Undo(); } private void 恢复ToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Redo();
C# winform中文本框限制只能输入数字和字母,退格键
C#  winform中文本框限制只能输入数字和字母,退格键: 选择文本框的KeyPress事件,添加以下代码 private void textBox_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= 'a' && e.KeyChar = 'A' && e.KeyChar
简单计算器
char fln; double mumble, temp; #region//数字键 private void button1_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + "1"; } private void button2_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + "2"; } private void button3_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + "3"; } private void button4_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + "4"; } private void button5_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + "5"; } private void button6_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + "6"; } textBox1.Text = textBox1.Text + ".";
C#串口实例 源代码
namespace 串口实例 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { //手动发送 SendMsg(); } private void SendMsg() { this.serialPort1.Write(this.txtSend.Text); } #region 控制输入数字 private void ComboBox_TextUpdate(object sender, EventArgs e) { ComboBox cbo = sender as ComboBox; int n; if (!int.TryParse(cbo.Text, out n)) { cbo.Text = cbo.Text.Substring(0, cbo.Text.Length - 1); } else { if (n <= 0) { cbo.Text = cbo.Text.Substring(0, cbo.Text.Length - 1); } } } private void txtTime_TextChanged(object sender, EventArgs e) { TextBox text = sender as TextBox; int n; if (!int.TryParse(text.Text, out n)) { text.Text = text.Text.Substring(0, text.Text.Length - 1); } else { if (n <= 0) { text.Text = text.Text.Substring(0, text.Text.Length - 1); } else { this.timer1.Interval = n; } } } #endregion /// <summary> /// 清空显示文本框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnClear_Click(object sender, EventArgs e) { this.txtRecive.Clear(); } private void timer1_Tick(object sender, EventArgs e) { SendMsg(); } private void cbtSend_CheckedChanged(object sender, EventArgs e) { CheckBox check = sender as CheckBox; if (check.Checked) { this.timer1.Start(); } else { this.timer1.Stop(); } } /// <summary> /// 接收返回的数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { string a=""; if (this.cbkShow16.Checked) { //十六进制显示 a = this.serialPort1.ReadExisting(); } else { //字符串显示 byte[] by = new byte[this.serialPort1.BytesToRead]; this.serialPort1.Read(by, 0, this.serialPort1.BytesToRead); a = Encoding.ASCII.GetString(by); } this.txtRecive.AppendText(a); this.txtRecive.ScrollToCaret(); } private void Form1_Load(object sender, EventArgs e) { //加载 this.serialPort1.RtsEnable = true; button1_Click(this.btnOpen, null); } private void button1_Click(object sender, EventArgs e) { Button btn = sender as Button; if (btn.Text == "打开端口") { try { this.serialPort1.PortName = this.cboPortName.Text; this.serialPort1.BaudRate = Convert.ToInt32(this.cboRaudRate.Text); this.serialPort1.DataBits = Convert.ToInt32(this.cboDataBits.Text); this.serialPort1.ReceivedBytesThreshold = Convert.ToInt32(this.cboReceivedBytesThreshold.Text); this.serialPort1.Open(); btn.Text = "关闭端口"; } catch { MessageBox.Show("打开端口失败,请检查端口是否被占用."); } } else { this.serialPort1.Close(); btn.Text = "打开端口"; } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { this.serialPort1.Close(); } catch { } } } }
用C#把winform中的databinding信息取出,并附给datarow
  private void button1_Click(object sender, System.EventArgs e)  {   try   {    object ds ;    string bindingField,propertyName;    System.Data.DataRow dr = objdataSet.Tables[0].NewRow();    foreach(C
关闭