/// <summary> /// 设置能力的当前值 /// </summary> /// <param name="control"></param> /// <param name="capInfo"></param> private void SetCurrentValue(Control control, CapInfo capInfo) { if (!control.IsEnabled) { return; } bool twOk; string enumStr = null; if (control is ComboBox) { ComboBox comboBox = control as ComboBox; //对于压缩算法和文件格式 if (capInfo.CapId == TwCap.ICAP_COMPRESSION || capInfo.CapId == TwCap.ICAP_IMAGEFILEFORMAT) { CapInfo xferCapInfo = twSession.GetScannerCap(TwCap.ICAP_XferMech); if (xferCapInfo.CurrentIntStr == "0") // native模式 { // 只设置到控件 bool OK = SetCurrentValueOfComboBox(comboBox, capInfo); if (!OK) { comboBox.SelectedIndex = 0; enumStr = (comboBox.SelectedItem as ComboBoxItem).Content.ToString(); capInfo.CurrentIntStr = twSession.ConvertEnumStringToIntString(capInfo.CapId, enumStr); } return; } } // 设置用户保存的设置 twOk = SetOneValue(comboBox, capInfo); if (twOk) { return; } // 获取默认值 capInfo.CurrentIntStr = capInfo.DefaultIntStr; // 设置默认值 twOk = SetOneValue(comboBox, capInfo); if (twOk) { return; } // 设置默认值失败,选择一个值进行设置 comboBox.SelectedIndex = comboBox.Items.Count / 2; string enumString = (comboBox.SelectedItem as ComboBoxItem).Content.ToString(); string intString = twSession.ConvertEnumStringToIntString(capInfo.CapId, enumString); capInfo.CurrentIntStr = intString; twOk = SetOneValue(comboBox, capInfo); } else if (control is CheckBox) { CheckBox checkBox = control as CheckBox; SetOneValue(checkBox, capInfo); } }