private void ModifyRegion() { bool isChs = LanguageVersion == ProCommon.Communal.Language.Chinese; string txt = isChs ? "修改区域异常!" : "Error occured when modify region!"; string caption = isChs ? "警告信息" : "Warning Message"; HalconDotNet.HTuple mr, mc, mbtntype; HalconDotNet.HObject tmpModify = null; HalconDotNet.HObject tmpKeep = null, tmpSelect = null; HalconDotNet.HOperatorSet.GenEmptyObj(out tmpKeep); HalconDotNet.HOperatorSet.GenEmptyObj(out tmpSelect); int cnt = 0; this.hwndcDisplay.Focus(); UpdateRegionForDisplay(); while (_isModifying) { try { HalconDotNet.HOperatorSet.GetMposition(this.hwndcDisplay.HalconWindow, out mr, out mc, out mbtntype); if (_hoBrushRegion != null && _hoBrushRegion.IsInitialized()) { _hoBrushRegion.Dispose(); } HalconDotNet.HOperatorSet.GenRectangle1(out _hoBrushRegion, mr - _zoomFactorForBrush, mc - _zoomFactorForBrush, mr + _zoomFactorForBrush, mc + _zoomFactorForBrush); UpdateRegionForDisplay(); if (mbtntype.TupleEqual(new HalconDotNet.HTuple(1))) //按下鼠标左键 { HalconDotNet.HOperatorSet.Difference(_hoSelectedRegion, _hoBrushRegion, out tmpModify); _hoSelectedRegion.Dispose(); _hoSelectedRegion = tmpModify; //若初始区域为数组型 cnt = _hoModifiedRegion.CountObj(); for (int i = 0; i < cnt; i++) { tmpSelect.Dispose(); //未选择的区域,不修改,需要保留 if (i != this.lstbRegion.SelectedIndex) { HalconDotNet.HOperatorSet.SelectObj(_hoModifiedRegion, out tmpSelect, i + 1); } //选择的区域,更新为上述修改后的区域 else { HalconDotNet.HOperatorSet.CopyObj(_hoSelectedRegion, out tmpSelect, 1, 1); } HalconDotNet.HOperatorSet.ConcatObj(tmpKeep, tmpSelect, out tmpKeep); } tmpSelect.Dispose(); _hoModifiedRegion.Dispose(); _hoModifiedRegion = tmpKeep; HalconDotNet.HOperatorSet.WaitSeconds(0.001); } else if (mbtntype.TupleEqual(new HalconDotNet.HTuple(4))) //按下鼠标右键 { _isModifying = false; if (_hoBrushRegion != null && _hoBrushRegion.IsInitialized()) { _hoBrushRegion.Dispose(); } //UpdateRegionForDisplay(); _isModified = true; } } catch (HalconDotNet.HalconException hex) { //_isModifying = false; //ProCommon.DerivedForm.FrmMsgBox.Show(txt + "\r\n" + hex.Message, caption, // ProCommon.DerivedForm.MyButtons.OK, // ProCommon.DerivedForm.MyIcon.Error, isChs); } //System.Threading.Thread.Sleep(1); Application.DoEvents(); } }