This commit is contained in:
@@ -2,6 +2,7 @@ using LiveCharts;
|
||||
using LiveCharts.Wpf;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.Integration;
|
||||
|
||||
@@ -24,99 +25,111 @@ namespace 全自动水压检测仪
|
||||
/// </summary>
|
||||
public void InitializeChart(Control targetPanel)
|
||||
{
|
||||
if (targetPanel == null)
|
||||
throw new ArgumentNullException(nameof(targetPanel));
|
||||
|
||||
// 清除占位文字
|
||||
targetPanel.Text = null;
|
||||
|
||||
// 初始化数据集合
|
||||
_pressureValues = new ChartValues<double>();
|
||||
_temperatureValues = new ChartValues<double>();
|
||||
_timeLabels = new ChartValues<string>();
|
||||
|
||||
// 创建WPF图表控件
|
||||
_chart = new LiveCharts.Wpf.CartesianChart
|
||||
targetPanel.Invoke(new Action(() =>
|
||||
{
|
||||
Background = System.Windows.Media.Brushes.White,
|
||||
DisableAnimations = false,
|
||||
Hoverable = true,
|
||||
DataTooltip = null,
|
||||
LegendLocation = LegendLocation.Top
|
||||
};
|
||||
if (targetPanel == null)
|
||||
throw new ArgumentNullException(nameof(targetPanel));
|
||||
|
||||
// 配置X轴(时间轴)
|
||||
_chart.AxisX.Add(new Axis
|
||||
{
|
||||
Title = "时间",
|
||||
Labels = _timeLabels,
|
||||
FontSize = 12,
|
||||
Foreground = System.Windows.Media.Brushes.Black,
|
||||
Separator = new LiveCharts.Wpf.Separator
|
||||
// 清除占位文字
|
||||
targetPanel.Text = null;
|
||||
|
||||
// 初始化数据集合
|
||||
_pressureValues = new ChartValues<double>();
|
||||
_temperatureValues = new ChartValues<double>();
|
||||
_timeLabels = new ChartValues<string>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 创建WPF图表控件
|
||||
_chart = new LiveCharts.Wpf.CartesianChart
|
||||
{
|
||||
Step = 5,
|
||||
IsEnabled = true
|
||||
}
|
||||
});
|
||||
Background = System.Windows.Media.Brushes.White,
|
||||
DisableAnimations = false,
|
||||
Hoverable = true,
|
||||
DataTooltip = null,
|
||||
LegendLocation = LegendLocation.Top
|
||||
};
|
||||
|
||||
// 配置Y轴(压力)
|
||||
_chart.AxisY.Add(new Axis
|
||||
{
|
||||
Title = "压力 (MPa)",
|
||||
FontSize = 12,
|
||||
Foreground = System.Windows.Media.Brushes.Blue,
|
||||
LabelFormatter = value => value.ToString("F2"),
|
||||
MinValue = 0
|
||||
});
|
||||
|
||||
// 配置第二Y轴(压力设定值)
|
||||
_chart.AxisY.Add(new Axis
|
||||
{
|
||||
Title = "压力设定值 (MPa)",
|
||||
FontSize = 12,
|
||||
Foreground = System.Windows.Media.Brushes.Red,
|
||||
LabelFormatter = value => value.ToString("F2"),
|
||||
Position = AxisPosition.RightTop,
|
||||
MinValue = 0
|
||||
});
|
||||
// 配置X轴(时间轴)
|
||||
_chart.AxisX.Add(new Axis
|
||||
{
|
||||
Title = "时间",
|
||||
Labels = _timeLabels,
|
||||
FontSize = 12,
|
||||
Foreground = System.Windows.Media.Brushes.Black,
|
||||
Separator = new LiveCharts.Wpf.Separator
|
||||
{
|
||||
Step = 5,
|
||||
IsEnabled = true
|
||||
}
|
||||
});
|
||||
|
||||
// 添加压力曲线
|
||||
_chart.Series.Add(new LineSeries
|
||||
{
|
||||
Title = "实时压力",
|
||||
Values = _pressureValues,
|
||||
Stroke = System.Windows.Media.Brushes.Blue,
|
||||
Fill = System.Windows.Media.Brushes.Transparent,
|
||||
PointGeometry = DefaultGeometries.Circle,
|
||||
PointGeometrySize = 5,
|
||||
StrokeThickness = 2,
|
||||
LineSmoothness = 0.3,
|
||||
ScalesYAt = 0
|
||||
});
|
||||
// 配置Y轴(压力)
|
||||
_chart.AxisY.Add(new Axis
|
||||
{
|
||||
Title = "压力 (MPa)",
|
||||
FontSize = 12,
|
||||
Foreground = System.Windows.Media.Brushes.Blue,
|
||||
LabelFormatter = value => value.ToString("F2"),
|
||||
MinValue = 0
|
||||
});
|
||||
|
||||
// 添加压力设定值曲线
|
||||
_chart.Series.Add(new LineSeries
|
||||
{
|
||||
Title = "压力设定值",
|
||||
Values = _temperatureValues,
|
||||
Stroke = System.Windows.Media.Brushes.Red,
|
||||
Fill = System.Windows.Media.Brushes.Transparent,
|
||||
PointGeometry = DefaultGeometries.Diamond,
|
||||
PointGeometrySize = 5,
|
||||
StrokeThickness = 2,
|
||||
LineSmoothness = 0.3,
|
||||
ScalesYAt = 1
|
||||
});
|
||||
// 配置第二Y轴(压力设定值)
|
||||
_chart.AxisY.Add(new Axis
|
||||
{
|
||||
Title = "压力设定值 (MPa)",
|
||||
FontSize = 12,
|
||||
Foreground = System.Windows.Media.Brushes.Red,
|
||||
LabelFormatter = value => value.ToString("F2"),
|
||||
Position = AxisPosition.RightTop,
|
||||
MinValue = 0
|
||||
});
|
||||
|
||||
// 创建ElementHost以承载WPF控件
|
||||
_chartHost = new ElementHost
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
Child = _chart
|
||||
};
|
||||
// 添加压力曲线
|
||||
_chart.Series.Add(new LineSeries
|
||||
{
|
||||
Title = "实时压力",
|
||||
Values = _pressureValues,
|
||||
Stroke = System.Windows.Media.Brushes.Blue,
|
||||
Fill = System.Windows.Media.Brushes.Transparent,
|
||||
PointGeometry = DefaultGeometries.Circle,
|
||||
PointGeometrySize = 5,
|
||||
StrokeThickness = 2,
|
||||
LineSmoothness = 0.3,
|
||||
ScalesYAt = 0
|
||||
});
|
||||
|
||||
// 添加到目标面板
|
||||
targetPanel.Controls.Add(_chartHost);
|
||||
// 添加压力设定值曲线
|
||||
_chart.Series.Add(new LineSeries
|
||||
{
|
||||
Title = "压力设定值",
|
||||
Values = _temperatureValues,
|
||||
Stroke = System.Windows.Media.Brushes.Red,
|
||||
Fill = System.Windows.Media.Brushes.Transparent,
|
||||
PointGeometry = DefaultGeometries.Diamond,
|
||||
PointGeometrySize = 5,
|
||||
StrokeThickness = 2,
|
||||
LineSmoothness = 0.3,
|
||||
ScalesYAt = 1
|
||||
});
|
||||
|
||||
// 创建ElementHost以承载WPF控件
|
||||
_chartHost = new ElementHost
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
Child = _chart
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 添加到目标面板
|
||||
targetPanel.Controls.Add(_chartHost);
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
1159
全自动水压检测仪/NormalTemperatureMode.Designer.cs
generated
1159
全自动水压检测仪/NormalTemperatureMode.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@@ -787,11 +787,13 @@ namespace 全自动水压检测仪
|
||||
bool currentLowTempState = modbusResults.LowStatus[0];
|
||||
|
||||
uiLight1.State = currentLowTempState ? UILightState.On : UILightState.Off;
|
||||
|
||||
|
||||
|
||||
// 如果温度模式状态发生变化,更新控件可见性
|
||||
if (previousLowTempState != currentLowTempState)
|
||||
{
|
||||
UpdateControlsVisibilityByMode();
|
||||
//UpdateControlsVisibilityByMode();
|
||||
UpdateControlsVisibilityByModeOptimized();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,11 +804,13 @@ namespace 全自动水压检测仪
|
||||
bool currentHighTempState = modbusResults.HighStatus[0];
|
||||
|
||||
uiLight2.State = currentHighTempState ? UILightState.On : UILightState.Off;
|
||||
|
||||
|
||||
|
||||
// 如果温度模式状态发生变化,更新控件可见性
|
||||
if (previousHighTempState != currentHighTempState)
|
||||
{
|
||||
UpdateControlsVisibilityByMode();
|
||||
//UpdateControlsVisibilityByMode();
|
||||
UpdateControlsVisibilityByModeOptimized();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -926,6 +930,7 @@ namespace 全自动水压检测仪
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void NormalTemperatureMode_Load(object sender, EventArgs e)
|
||||
{
|
||||
@@ -969,13 +974,15 @@ namespace 全自动水压检测仪
|
||||
ma = new Function(_modbusMaster);
|
||||
c = new DataChange();
|
||||
// 暂时注释
|
||||
_modbusMaster?.WriteSingleCoil(1, 10030, true);
|
||||
//_modbusMaster?.WriteSingleCoil(1, 10030, false);
|
||||
|
||||
|
||||
boolSignal1.OnRisingEdge += BoolSignal1_OnRisingEdge;
|
||||
|
||||
// 初始化图表
|
||||
try
|
||||
{
|
||||
_chartManager.InitializeChart(uiPanel_ChartPlaceholder);
|
||||
//_chartManager.InitializeChart(uiPanel_ChartPlaceholder);
|
||||
Debug.WriteLine("[NormalTemperatureMode] 图表初始化成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1283,9 +1290,9 @@ namespace 全自动水压检测仪
|
||||
try
|
||||
{
|
||||
// 暂停定时器,避免并发访问Modbus
|
||||
_readTimer?.Stop();
|
||||
_readTimerTwo?.Stop();
|
||||
_alarmMonitorTimer?.Stop();
|
||||
//_readTimer?.Stop();
|
||||
//_readTimerTwo?.Stop();
|
||||
//_alarmMonitorTimer?.Stop();
|
||||
|
||||
// 在后台线程执行Modbus操作
|
||||
await Task.Run(() =>
|
||||
@@ -1296,10 +1303,9 @@ namespace 全自动水压检测仪
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"[uiSwitch1_Click] 切换模式失败: {ex.Message}");
|
||||
SafeInvoke(() =>
|
||||
{
|
||||
MessageBox.Show($"切换模式失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
Debug.WriteLine($"切换模式失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1308,28 +1314,28 @@ namespace 全自动水压检测仪
|
||||
await Task.Delay(800);
|
||||
|
||||
// 更新控件可见性
|
||||
SafeInvoke(() =>
|
||||
{
|
||||
UpdateControlsVisibilityByMode();
|
||||
//SafeInvoke(() =>
|
||||
//{
|
||||
// UpdateControlsVisibilityByMode();
|
||||
|
||||
// 更新图表模式
|
||||
bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
|
||||
_chartManager?.UpdateChartMode(isHighTempMode);
|
||||
});
|
||||
// // 更新图表模式
|
||||
// bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
|
||||
// _chartManager?.UpdateChartMode(isHighTempMode);
|
||||
//});
|
||||
|
||||
// 恢复定时器
|
||||
_readTimer?.Start();
|
||||
_readTimerTwo?.Start();
|
||||
_alarmMonitorTimer?.Start();
|
||||
//// 恢复定时器
|
||||
//_readTimer?.Start();
|
||||
//_readTimerTwo?.Start();
|
||||
//_alarmMonitorTimer?.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"[uiSwitch1_Click] 异常: {ex.Message}");
|
||||
|
||||
// 确保定时器恢复
|
||||
_readTimer?.Start();
|
||||
_readTimerTwo?.Start();
|
||||
_alarmMonitorTimer?.Start();
|
||||
//// 确保定时器恢复
|
||||
//_readTimer?.Start();
|
||||
//_readTimerTwo?.Start();
|
||||
//_alarmMonitorTimer?.Start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1393,7 +1399,7 @@ namespace 全自动水压检测仪
|
||||
}
|
||||
|
||||
// 初始化时根据当前模式更新控件可见性
|
||||
UpdateControlsVisibilityByMode();
|
||||
//UpdateControlsVisibilityByMode();
|
||||
}
|
||||
|
||||
//返回录入系统
|
||||
@@ -1636,126 +1642,205 @@ namespace 全自动水压检测仪
|
||||
/// 常温模式:显示常温相关参数(常温实时液位、常温加水)
|
||||
/// 高温模式:显示高温相关参数(高温实时液位、箱体温度、出口温度、高温加水、水箱加热)
|
||||
/// </summary>
|
||||
private void UpdateControlsVisibilityByMode()
|
||||
//private void UpdateControlsVisibilityByMode()
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// // 判断当前是否为高温模式(uiLight2亮起表示高温模式)
|
||||
// bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
|
||||
// bool isLowTempMode = uiLight1 != null && uiLight1.State == UILightState.On;
|
||||
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 开始更新 - 高温模式: {isHighTempMode}, 常温模式: {isLowTempMode}");
|
||||
|
||||
// // ========== 高温模式专属控件(高温模式显示,常温模式隐藏) ==========
|
||||
|
||||
// // 高温实时液位(mm) - uiPanel31包含uiLabel7, uiLabel8, uiLabel34, uiProcessBar2
|
||||
// if (uiPanel31 != null && !uiPanel31.IsDisposed)
|
||||
// {
|
||||
// uiPanel31.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel31(高温液位) Visible = {isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 箱体温度(°C) - uiPanel35包含uiLabel42, uiLabel43(实时数据监控区域)
|
||||
// if (uiPanel35 != null && !uiPanel35.IsDisposed)
|
||||
// {
|
||||
// uiPanel35.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel35(箱体温度) Visible = {isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 出口温度(°C) - uiPanel33包含uiLabel38, uiLabel39(实时数据监控区域)
|
||||
// if (uiPanel33 != null && !uiPanel33.IsDisposed)
|
||||
// {
|
||||
// uiPanel33.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel33(出口温度) Visible = {isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 高温加水按钮 - uiButton5
|
||||
// if (uiButton5 != null && !uiButton5.IsDisposed)
|
||||
// {
|
||||
// uiButton5.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton5(高温加水) Visible = {isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 高温加水指示灯 - uiLight11
|
||||
// if (uiPanel43 != null && !uiPanel43.IsDisposed)
|
||||
// {
|
||||
// uiPanel43.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel43(高温加水指示灯) Visible = {isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 水箱加热按钮 - uiButton4(用户操作设定区域)
|
||||
// if (uiButton4 != null && !uiButton4.IsDisposed)
|
||||
// {
|
||||
// uiButton4.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton4(水箱加热) Visible = {isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 出口温度判定设置 - uiLabel48和uiTextBox9(用户操作设定区域)
|
||||
// if (uiLabel48 != null && !uiLabel48.IsDisposed)
|
||||
// {
|
||||
// uiLabel48.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel48(出口温度标签) Visible = {isHighTempMode}");
|
||||
// }
|
||||
// if (uiTextBox9 != null && !uiTextBox9.IsDisposed)
|
||||
// {
|
||||
// uiTextBox9.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox9(出口温度输入) Visible = {isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 写入按钮 - uiButton8(用于写入联络单号和件号数据到PLC,常温和高温模式都需要)
|
||||
// // 注意:写入按钮应该始终显示,因为联络单号和件号在两种模式下都需要
|
||||
// if (uiButton8 != null && !uiButton8.IsDisposed)
|
||||
// {
|
||||
// uiButton8.Visible = true; // 始终显示写入按钮
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton8(写入按钮) Visible = true (始终显示)");
|
||||
// }
|
||||
|
||||
// // 箱体温度设置 - uiLabel37和uiTextBox4(用户操作设定区域)
|
||||
// if (uiLabel37 != null && !uiLabel37.IsDisposed)
|
||||
// {
|
||||
// uiLabel37.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel37(箱体温度标签) Visible = {isHighTempMode}");
|
||||
// }
|
||||
// if (uiTextBox4 != null && !uiTextBox4.IsDisposed)
|
||||
// {
|
||||
// uiTextBox4.Visible = isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox4(箱体温度输入) Visible = {isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // ========== 常温模式专属控件(常温模式显示,高温模式隐藏) ==========
|
||||
|
||||
// // 常温实时液位(mm) - uiPanel23包含uiLabel12, uiLabel16, uiLabel17, uiProcessBar1
|
||||
// if (uiPanel23 != null && !uiPanel23.IsDisposed)
|
||||
// {
|
||||
// uiPanel23.Visible = !isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel23(常温液位) Visible = {!isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 常温加水按钮 - uiButton13
|
||||
// if (uiButton13 != null && !uiButton13.IsDisposed)
|
||||
// {
|
||||
// uiButton13.Visible = !isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton13(常温加水) Visible = {!isHighTempMode}");
|
||||
// }
|
||||
|
||||
// // 常温加水指示灯 - uiLight6
|
||||
// if (uiPanel38 != null && !uiPanel38.IsDisposed)
|
||||
// {
|
||||
// uiPanel38.Visible = !isHighTempMode;
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel38(常温加水指示灯) Visible = {!isHighTempMode}");
|
||||
// }
|
||||
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 模式切换完成 - 高温模式: {isHighTempMode}");
|
||||
// }
|
||||
// catch (ObjectDisposedException ex)
|
||||
// {
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 控件已释放: {ex.Message}");
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 更新控件可见性失败: {ex.Message}");
|
||||
// Debug.WriteLine($"[UpdateControlsVisibilityByMode] 堆栈跟踪: {ex.StackTrace}");
|
||||
// }
|
||||
//}
|
||||
private void UpdateControlsVisibilityByModeOptimized()
|
||||
{
|
||||
// 在更新前暂停布局计算
|
||||
this.SuspendLayout();
|
||||
|
||||
try
|
||||
{
|
||||
// 判断当前是否为高温模式(uiLight2亮起表示高温模式)
|
||||
bool isHighTempMode = uiLight2 != null && uiLight2.State == UILightState.On;
|
||||
bool isLowTempMode = uiLight1 != null && uiLight1.State == UILightState.On;
|
||||
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 开始更新 - 高温模式: {isHighTempMode}, 常温模式: {isLowTempMode}");
|
||||
Debug.WriteLine($"[优化版] 高温模式: {isHighTempMode}");
|
||||
|
||||
// ========== 高温模式专属控件(高温模式显示,常温模式隐藏) ==========
|
||||
|
||||
// 高温实时液位(mm) - uiPanel31包含uiLabel7, uiLabel8, uiLabel34, uiProcessBar2
|
||||
if (uiPanel31 != null && !uiPanel31.IsDisposed)
|
||||
{
|
||||
uiPanel31.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel31(高温液位) Visible = {isHighTempMode}");
|
||||
}
|
||||
|
||||
// 箱体温度(°C) - uiPanel35包含uiLabel42, uiLabel43(实时数据监控区域)
|
||||
if (uiPanel35 != null && !uiPanel35.IsDisposed)
|
||||
{
|
||||
uiPanel35.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel35(箱体温度) Visible = {isHighTempMode}");
|
||||
}
|
||||
|
||||
// 出口温度(°C) - uiPanel33包含uiLabel38, uiLabel39(实时数据监控区域)
|
||||
if (uiPanel33 != null && !uiPanel33.IsDisposed)
|
||||
{
|
||||
uiPanel33.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel33(出口温度) Visible = {isHighTempMode}");
|
||||
}
|
||||
|
||||
// 高温加水按钮 - uiButton5
|
||||
if (uiButton5 != null && !uiButton5.IsDisposed)
|
||||
{
|
||||
uiButton5.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton5(高温加水) Visible = {isHighTempMode}");
|
||||
}
|
||||
|
||||
// 高温加水指示灯 - uiLight11
|
||||
if (uiPanel43 != null && !uiPanel43.IsDisposed)
|
||||
{
|
||||
uiPanel43.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel43(高温加水指示灯) Visible = {isHighTempMode}");
|
||||
}
|
||||
|
||||
// 水箱加热按钮 - uiButton4(用户操作设定区域)
|
||||
if (uiButton4 != null && !uiButton4.IsDisposed)
|
||||
{
|
||||
uiButton4.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton4(水箱加热) Visible = {isHighTempMode}");
|
||||
}
|
||||
|
||||
// 出口温度判定设置 - uiLabel48和uiTextBox9(用户操作设定区域)
|
||||
if (uiLabel48 != null && !uiLabel48.IsDisposed)
|
||||
{
|
||||
uiLabel48.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel48(出口温度标签) Visible = {isHighTempMode}");
|
||||
}
|
||||
if (uiTextBox9 != null && !uiTextBox9.IsDisposed)
|
||||
{
|
||||
uiTextBox9.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox9(出口温度输入) Visible = {isHighTempMode}");
|
||||
}
|
||||
|
||||
// 写入按钮 - uiButton8(用于写入联络单号和件号数据到PLC,常温和高温模式都需要)
|
||||
// 注意:写入按钮应该始终显示,因为联络单号和件号在两种模式下都需要
|
||||
if (uiButton8 != null && !uiButton8.IsDisposed)
|
||||
{
|
||||
uiButton8.Visible = true; // 始终显示写入按钮
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton8(写入按钮) Visible = true (始终显示)");
|
||||
}
|
||||
|
||||
// 箱体温度设置 - uiLabel37和uiTextBox4(用户操作设定区域)
|
||||
if (uiLabel37 != null && !uiLabel37.IsDisposed)
|
||||
{
|
||||
uiLabel37.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiLabel37(箱体温度标签) Visible = {isHighTempMode}");
|
||||
}
|
||||
if (uiTextBox4 != null && !uiTextBox4.IsDisposed)
|
||||
{
|
||||
uiTextBox4.Visible = isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiTextBox4(箱体温度输入) Visible = {isHighTempMode}");
|
||||
}
|
||||
// 批量更新,减少中间状态
|
||||
UpdateHighTempControls(isHighTempMode);
|
||||
UpdateNormalTempControls(!isHighTempMode);
|
||||
|
||||
// ========== 常温模式专属控件(常温模式显示,高温模式隐藏) ==========
|
||||
|
||||
// 常温实时液位(mm) - uiPanel23包含uiLabel12, uiLabel16, uiLabel17, uiProcessBar1
|
||||
if (uiPanel23 != null && !uiPanel23.IsDisposed)
|
||||
{
|
||||
uiPanel23.Visible = !isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel23(常温液位) Visible = {!isHighTempMode}");
|
||||
}
|
||||
|
||||
// 常温加水按钮 - uiButton13
|
||||
if (uiButton13 != null && !uiButton13.IsDisposed)
|
||||
{
|
||||
uiButton13.Visible = !isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiButton13(常温加水) Visible = {!isHighTempMode}");
|
||||
}
|
||||
|
||||
// 常温加水指示灯 - uiLight6
|
||||
if (uiPanel38 != null && !uiPanel38.IsDisposed)
|
||||
{
|
||||
uiPanel38.Visible = !isHighTempMode;
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] uiPanel38(常温加水指示灯) Visible = {!isHighTempMode}");
|
||||
}
|
||||
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 模式切换完成 - 高温模式: {isHighTempMode}");
|
||||
// 确保写入按钮始终显示
|
||||
if (uiButton8 != null) uiButton8.Visible = true;
|
||||
}
|
||||
catch (ObjectDisposedException ex)
|
||||
finally
|
||||
{
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 控件已释放: {ex.Message}");
|
||||
// 恢复布局计算,只进行一次重绘
|
||||
this.ResumeLayout(true);
|
||||
|
||||
// 如果需要,手动设置窗体大小固定
|
||||
if (this.FormBorderStyle == FormBorderStyle.Sizable)
|
||||
{
|
||||
// 临时锁定窗体大小
|
||||
this.MaximumSize = this.Size;
|
||||
this.MinimumSize = this.Size;
|
||||
|
||||
// 稍后恢复(可选)
|
||||
Task.Delay(100).ContinueWith(_ =>
|
||||
{
|
||||
if (!this.IsDisposed)
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
this.MaximumSize = new Size(0, 0);
|
||||
this.MinimumSize = new Size(0, 0);
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
}
|
||||
|
||||
// 分开更新方法
|
||||
private void UpdateHighTempControls(bool visible)
|
||||
{
|
||||
Control[] highTempControls = {
|
||||
uiPanel31, uiPanel35, uiPanel33, uiButton5, uiPanel43,
|
||||
uiButton4, uiLabel48, uiTextBox9, uiLabel37, uiTextBox4
|
||||
};
|
||||
|
||||
foreach (var control in highTempControls)
|
||||
{
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 更新控件可见性失败: {ex.Message}");
|
||||
Debug.WriteLine($"[UpdateControlsVisibilityByMode] 堆栈跟踪: {ex.StackTrace}");
|
||||
if (control != null && !control.IsDisposed)
|
||||
{
|
||||
control.Visible = visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateNormalTempControls(bool visible)
|
||||
{
|
||||
Control[] normalTempControls = {
|
||||
uiPanel23, uiButton13, uiPanel38
|
||||
};
|
||||
|
||||
foreach (var control in normalTempControls)
|
||||
{
|
||||
if (control != null && !control.IsDisposed)
|
||||
{
|
||||
control.Visible = visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -209,14 +209,14 @@ namespace 全自动水压检测仪
|
||||
this.tempModePanel.Controls.Add(this.uiLight2_Status);
|
||||
|
||||
// 当前模式显示
|
||||
var currentModeLabel = new Sunny.UI.UILabel();
|
||||
currentModeLabel.Location = new System.Drawing.Point(520, 65);
|
||||
currentModeLabel.Size = new System.Drawing.Size(120, 30);
|
||||
currentModeLabel.Text = "当前模式:";
|
||||
currentModeLabel.Font = new System.Drawing.Font("微软雅黑", 11F);
|
||||
currentModeLabel.ForeColor = System.Drawing.Color.FromArgb(100, 100, 100);
|
||||
currentModeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
this.tempModePanel.Controls.Add(currentModeLabel);
|
||||
//var currentModeLabel = new Sunny.UI.UILabel();
|
||||
//currentModeLabel.Location = new System.Drawing.Point(520, 65);
|
||||
//currentModeLabel.Size = new System.Drawing.Size(120, 30);
|
||||
//currentModeLabel.Text = "当前模式:";
|
||||
//currentModeLabel.Font = new System.Drawing.Font("微软雅黑", 11F);
|
||||
//currentModeLabel.ForeColor = System.Drawing.Color.FromArgb(100, 100, 100);
|
||||
//currentModeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
//this.tempModePanel.Controls.Add(currentModeLabel);
|
||||
|
||||
// uiLabel11_Status
|
||||
this.uiLabel11_Status.Location = new System.Drawing.Point(640, 65);
|
||||
|
||||
Reference in New Issue
Block a user