网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

VS 2010 C# winform:[7]质量长度转化

时间:2024-10-19 18:16:46

1、首先,新建项目,新建窗体。

VS 2010 C# winform:[7]质量长度转化

2、拖入两个textbox框。一个用于输入textBox7,一个用于显示textBox8。其它添加Lable控件,显示单位。

VS 2010 C# winform:[7]质量长度转化

4、具体事件代码如下: private void textBox7_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 13 && e.KeyChar != 45 && e.KeyChar != 46) { e.Handled = true; } //输入为负号时,只能输入一次且只能输入一次 if (e.KeyChar == 45 && (((TextBox)sender).SelectionStart != 0 || ((TextBox)sender).Text.IndexOf("-") >= 0)) e.Handled = true; if (e.KeyChar == 46 && ((TextBox)sender).Text.IndexOf(".") >= 0) e.Handled = true; } private void textBox7_TextChanged(object sender, EventArgs e) { float n1 = 0; if (this.textBox7.Text == "") { n1 = 0; } else { n1 = float.Parse(this.textBox7.Text); } this.textBox8.Text = Convert.ToString(n1 * 2.2046); }

VS 2010 C# winform:[7]质量长度转化

6、如果对您有所帮助,请继续阅读我的其它经验,也可以投票支持我。谢谢。

© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com