string json = File.ReadAllText("tsconfig1.json"); dynamic jsonObj = JsonConvert.DeserializeObject(json); dShutterValue = jsonObj["exposureTime"]; m_txt_Shutter.Text = dShutterValue.ToString("F2"); m_listCCamerInfo[m_nOperateID].m_objIGXFeatureControl.GetFloatFeature("ExposureTime").SetValue(dShutterValue); m_txt_Shutter.Clear(); try { if (!m_listCCamerInfo[m_nOperateID].m_bIsOpen) { return; } strValue = m_listCCamerInfo[m_nOperateID].m_objIGXFeatureControl.GetFloatFeature("ExposureTime").GetValue().ToString(); //浮点转字符串 try { dShutterValue = Convert.ToDouble(m_txt_Shutter.Text);//把文本框的值换成double,给dShutterValue } catch (Exception) { MessageBox.Show("请输入正确的曝光值"); m_txt_Shutter.Text = strValue; return; }c#窗体的文本框被json文件赋值后无法继续接收键盘输入的值,怎样利用m_txt_Shutter.Clear();语句,使文本框被赋值后可以继续接受键盘输入的值
时间: 2024-02-10 12:26:17 浏览: 160
Newtonsoft.Json.dll
To allow the text box to continue accepting keyboard input after being assigned a value from the JSON file, you can remove the `m_txt_Shutter.Clear()` statement. This statement clears the current text in the text, which is why it appears that the text box cannot receive keyboard input after being assigned a value.
Here is the updated code:
```csharp
string json = File.ReadAllText("tsconfig1.json");
dynamic jsonObj = JsonConvert.DeserializeObject(json);
dShutterValue = jsonObj["exposureTime"];
m_txt_Shutter.Text = dShutterValue.ToString("F2");
m_listCCamerInfo[m_nOperateID].m_objIGXFeatureControl.GetFloatFeature("ExposureTime").SetValue(dShutterValue);
try
{
if (!m_listCCamerInfo[m_nOperateID].m_bIsOpen)
{
return;
}
strValue = m_listCCamerInfo[m_nOperateID].m_objIGXFeatureControl.GetFloatFeature("ExposureTime").GetValue().ToString();
//浮点转字符串
try
{
dShutterValue = Convert.ToDouble(m_txt_Shutter.Text); //把文本框的值换成double,给dShutterValue
}
catch (Exception)
{
MessageBox.Show("请输入正确的曝光值");
m_txt_Shutter.Text = strValue;
return;
}
}
catch (Exception ex)
{
// Handle any other exceptions here
// Log the exception or display an error message
}
```
By removing the `m_txt_Shutter.Clear()` statement, the text box will retain the value assigned from the JSON file and will be able to receive keyboard input.
阅读全文