using System; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraEditors; namespace KepGridEditor { /// /// The form well adjust setting. /// public partial class FormWellAdjustSetting : DevExpress.XtraEditors.XtraForm { /// /// Gets or sets the well radius. /// public double WellRadius { get; set; } = 100; /// /// Gets or sets the value range. /// public double ValueRange { get; set; } = 10; /// /// Gets or sets the decreasing factor. /// public double DecreasingFactor { get; set; } = 0; /// /// Gets or sets the dilution factor (for RFB/IDW mode). /// public double DilutionFactor { get; set; } = 1.0; /// /// Gets the currently selected mode. /// public string SelectedMode => comboBoxEditMode.EditValue?.ToString() ?? "默认"; /// /// Initializes a new instance of the class. /// public FormWellAdjustSetting() { InitializeComponent(); // 在窗体加载后初始化界面状态 this.Load += FormWellAdjustSetting_Load; // 初始化文本框显示 this.txtRadius.Text = $"{WellRadius}"; this.txtDiffrence.Text = $"{ValueRange}"; this.txtFactor.Text = $"{DecreasingFactor}"; this.textEditDilution.Text = $"{DilutionFactor}"; } /// /// Initializes a new instance of the class with initial values. /// /// The well radius. /// The value range. /// The decreasing factor. public FormWellAdjustSetting(double wellRadius, double valueRange, double decreasingFactor) : this() { this.WellRadius = wellRadius; this.ValueRange = valueRange; this.DecreasingFactor = decreasingFactor; this.txtRadius.Text = $"{WellRadius}"; this.txtDiffrence.Text = $"{ValueRange}"; this.txtFactor.Text = $"{this.DecreasingFactor}"; } /// /// 窗体加载事件:设置默认选项并更新UI /// private void FormWellAdjustSetting_Load(object sender, EventArgs e) { if (comboBoxEditMode.Properties.Items.Contains("默认")) { comboBoxEditMode.EditValue = "默认"; UpdateUIForCurrentMode(); } } /// /// 根据当前选择的模式,更新控件的启用状态 /// private void UpdateUIForCurrentMode() { string mode = SelectedMode; bool isDefault = mode == "默认"; bool isRfbOrIdw = (mode == "RFB" || mode == "IDW"); // --- 默认模式:启用前三个参数 --- txtRadius.Enabled = isDefault; txtFactor.Enabled = isDefault; labelControl1.Enabled = isDefault; labelControl3.Enabled = isDefault; // --- RFB / IDW 模式:仅启用抽稀倍数 --- textEditDilution.Enabled = isRfbOrIdw; labelControl4.Enabled = isRfbOrIdw; // 可选:让非活动控件看起来更不显眼 txtRadius.Properties.Appearance.BackColor = isDefault ? SystemColors.Window : SystemColors.Control; txtFactor.Properties.Appearance.BackColor = isDefault ? SystemColors.Window : SystemColors.Control; textEditDilution.Properties.Appearance.BackColor = isRfbOrIdw ? SystemColors.Window : SystemColors.Control; } /// /// 当算法模式改变时,更新界面控件的可用性 /// private void comboBoxEditMode_SelectedIndexChanged(object sender, EventArgs e) { UpdateUIForCurrentMode(); } /// /// 确定按钮点击事件 /// private void btnOK_Click(object sender, EventArgs e) { try { string mode = SelectedMode; if (mode == "默认") { this.WellRadius = Convert.ToDouble(this.txtRadius.Text); this.ValueRange = Convert.ToDouble(this.txtDiffrence.Text); this.DecreasingFactor = Convert.ToDouble(this.txtFactor.Text); DilutionFactor = 0; // 不使用 } else { // RFB 或 IDW 模式:只读取抽稀倍数 if (!double.TryParse(textEditDilution.Text.Trim(), out double dilution) || dilution < 1) throw new ArgumentException($"【{mode}抽稀倍数】必须是大于1的数值。"); // 保存结果 DilutionFactor = dilution; // 其他参数不保存或设为默认 this.ValueRange = Convert.ToDouble(this.txtDiffrence.Text); DecreasingFactor = 0; } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } /// /// 取消按钮点击事件 /// private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } } }