VS 2010 C# winform:[7]质量长度转化
1、首先,新建项目,新建窗体。
![VS 2010 C# winform:[7]质量长度转化](https://exp-picture.cdn.bcebos.com/40d2d0e8b004541b763ab592869a310e1699a689.jpg)
2、拖入两个textbox框。一个用于输入textBox7,一个用于显示textBox8。其它添加Lable控件,显示单位。
![VS 2010 C# winform:[7]质量长度转化](https://exp-picture.cdn.bcebos.com/bbf95c406afec31440f0d25acac1b727ad539c89.jpg)
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]质量长度转化](https://exp-picture.cdn.bcebos.com/ad121888912ca5ca65ddd7fc8bfc77f7990e9489.jpg)
6、如果对您有所帮助,请继续阅读我的其它经验,也可以投票支持我。谢谢。