目录
1.转换textbox中的类型
try
{
int number = int.Parse(textBox1.Text.Trim()); // 将TextBox内容转换为int
MessageBox.Show($"转换成功: {number}");
}
catch (FormatException ex)
{
MessageBox.Show($"输入格式错误: {ex.Message}");
}
2.另一个cs文件获取窗体中textBox输入的
1.转换文本框为double类型并赋给变量
public static double initialWeight;//定义初始钢水变量
//获取钢水重量、手投物料重量,并转换格式传给机理
//textbox获取钢水总重
if (double.TryParse(textBox1.Text.Trim(), out double inputValue1))
{
initialWeight = inputValue1; // 给静态变量赋值
}
2.调用变量
public double CalCulateWeight()
{
//获取钢水总重、物料总重
double weight1 = TwoStationForm.initialWeight;
}
