void GetImgMessage(object sender, HalconDotNet.HMouseEventArgs e) { if (ViewController.Image != null) { HTuple row, col, grayValue, imageWidth, imageHeight; //int button_state; //double mouse_post_row, mouse_pose_col; //viewPort.HalconWindow.GetMpositionSubPix(out mouse_post_row, out mouse_pose_col, out button_state); row = e.Y; col = e.X; HOperatorSet.GetImageSize(ViewController.Image, out imageWidth, out imageHeight); if (col > 0 && row > 0 && col < imageWidth && row < imageHeight) { HOperatorSet.GetGrayval(ViewController.Image, row, col, out grayValue); } else { grayValue = 0; } toolStripStatusLabel1.Text = row.D.ToString("0.00"); toolStripStatusLabel2.Text = col.D.ToString("0.00"); toolStripStatusLabel3.Text = grayValue.ToString(); } else { toolStripStatusLabel1.Text = null; toolStripStatusLabel2.Text = null; toolStripStatusLabel3.Text = null; } }
/*************************************************************************/ /* Event handling for mouse */ /*************************************************************************/ private void mouseDown(object sender, HalconDotNet.HMouseEventArgs e) { mousePressed = true; int activeROIidx = -1; double scale; if (roiManager != null && (dispROI == MODE_INCLUDE_ROI)) { activeROIidx = roiManager.mouseDownAction(e.X, e.Y); } if (activeROIidx == -1) { switch (stateView) { case MODE_VIEW_MOVE: startX = e.X; startY = e.Y; break; case MODE_VIEW_NONE: break; case MODE_VIEW_ZOOMWINDOW: activateZoomWindow((int)e.X, (int)e.Y); break; default: break; } } //end of if }
public void HMouseDown(Object sender, HalconDotNet.HMouseEventArgs e) { if (this.HMouseClick != null) { this.HMouseClick(sender, e); } }
/*************************************************************************/ /* Event handling for mouse */ /*************************************************************************/ private void mouseDown(object sender, HalconDotNet.HMouseEventArgs e) { if (inMeasureLine) { return; } if (e.Button != MouseButtons.Left) { return; } mousePressed = true; int state; double x, y; try { viewPort.HalconWindow.GetMpositionSubPix(out y, out x, out state); } catch (HalconException) { return; } int activeROIidx = -1; if (roiManager != null && (showMode == ShowMode.IncludeROI)) { activeROIidx = roiManager.MouseDownAction(x, y); } if (activeROIidx == -1) { startX = x; startY = y; } }
/// <summary> /// UserControls under Windows Forms do not support the mouse wheel event. /// As a solution, the user can set his MouseWheel event in his form to /// call this method. /// Please notice that the Visual Studio Designer does not show this event. /// The reason is that UserControls do not support this type of event. /// Hence, you need to manually add it to the initialization code of your /// Windows Form, and set it to call the HSmartWindowControl_MouseWheel /// method of the HALCON Window Control. /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void HSmartWindowControl_MouseWheel(object sender, MouseEventArgs e) { HMouseEventArgs e1 = (HMouseEventArgs)null; try { if (this._zooming != HSmartWindowControl.ZoomContent.Off) { HTuple homMat2DIdentity; HOperatorSet.HomMat2dIdentity(out homMat2DIdentity); Point client = this.PointToClient(Cursor.Position); double rowImage; double columnImage; this._hwindow.ConvertCoordinatesWindowToImage((double)client.Y, (double)client.X, out rowImage, out columnImage); double num = e.Delta < 0 ? Math.Sqrt(2.0) : 1.0 / Math.Sqrt(2.0); if (this.HZoomContent == HSmartWindowControl.ZoomContent.WheelBackwardZoomsIn) { num = 1.0 / num; } for (int index = Math.Abs(e.Delta) / 120; index > 1; --index) { num *= e.Delta < 0 ? Math.Sqrt(2.0) : 1.0 / Math.Sqrt(2.0); } HTuple homMat2DScale; HOperatorSet.HomMat2dScale(homMat2DIdentity, (HTuple)num, (HTuple)num, (HTuple)columnImage, (HTuple)rowImage, out homMat2DScale); double l1; double c1; double l2; double c2; this.GetFloatPart(this._hwindow, out l1, out c1, out l2, out c2); HTuple qx1; HTuple qy1; HOperatorSet.AffineTransPoint2d(homMat2DScale, (HTuple)c1, (HTuple)l1, out qx1, out qy1); HTuple qx2; HTuple qy2; HOperatorSet.AffineTransPoint2d(homMat2DScale, (HTuple)c2, (HTuple)l2, out qx2, out qy2); e1 = this.ToHMouse(e); try { this._hwindow.SetPart((HTuple)qy1.D, (HTuple)qx1.D, (HTuple)qy2.D, (HTuple)qx2.D); } catch (Exception ex) { this._hwindow.SetPart((HTuple)l1, (HTuple)c1, (HTuple)l2, (HTuple)c2); } } } catch (HalconException ex) { if (this.HErrorNotify != null) { this.HErrorNotify(ex); } } if (this.HMouseWheel == null) { return; } this.HMouseWheel((object)this, e1); }
private void WindowFrame_MouseUp(object sender, MouseEventArgs e) { HMouseEventArgs e1 = (HMouseEventArgs)null; try { if (e.Button == MouseButtons.Left) { double rowImage; double columnImage; this._hwindow.ConvertCoordinatesWindowToImage((double)e.Y, (double)e.X, out rowImage, out columnImage); this._hwindow.SendMouseUpEvent((HTuple)rowImage, (HTuple)columnImage, this.MouseEventToInt(e)); this._left_button_down = false; } this._last_position.X = e.X; this._last_position.Y = e.Y; e1 = this.ToHMouse(e); } catch (HalconException ex) { if (this.HErrorNotify != null) { this.HErrorNotify(ex); } } if (this.HMouseUp == null) { return; } this.HMouseUp((object)this, e1); }
private void WindowFrame_MouseMove(object sender, MouseEventArgs e) { HMouseEventArgs e1 = (HMouseEventArgs)null; try { bool flag = false; if (this._left_button_down && this.InteractingWithDrawingObjs()) { double rowImage; double columnImage; this._hwindow.ConvertCoordinatesWindowToImage((double)e.Y, (double)e.X, out rowImage, out columnImage); flag = (HTuple)this._hwindow.SendMouseDragEvent((HTuple)rowImage, (HTuple)columnImage, this.MouseEventToInt(e)) == true; } if (!flag && this._left_button_down && this.HMoveContent) { this.HShiftWindowContents((double)(this._last_position.X - e.X), (double)(this._last_position.Y - e.Y)); } this._last_position.X = e.X; this._last_position.Y = e.Y; e1 = this.ToHMouse(e); } catch (HalconException ex) { if (this.HErrorNotify != null) { this.HErrorNotify(ex); } } if (this.HMouseMove == null) { return; } this.HMouseMove((object)this, e1); }
private void mouseClick(object sender, HalconDotNet.HMouseEventArgs e) { if (HMouseClick != null) { this.HMouseClick(sender, e); } }
protected virtual void OnHMouseWheel(HMouseEventArgs e) { if (this.HMouseWheel == null) { return; } this.HMouseWheel((object)this, e); }
private void HWindowControl0_HMouseDown(object sender, HalconDotNet.HMouseEventArgs e) { if (e.Button == MouseButtons.Left && crossCollection != null) { crossCollection.SetCrossActive(e.X, e.Y); Repaint(); _mouseDown = true; } }
/*******************************************************************/ private void mouseMoved(object sender, HalconDotNet.HMouseEventArgs e) { //关闭缩放事件 if (drawModel) { return; } double motionX, motionY; double posX, posY; double zoomZone; if (!mousePressed) { return; } if (roiManager != null && (roiManager.activeROIidx != -1) && (dispROI == MODE_INCLUDE_ROI)) { roiManager.mouseMoveAction(e.X, e.Y); } else if (stateView == MODE_VIEW_MOVE) { motionX = ((e.X - startX)); motionY = ((e.Y - startY)); if (((int)motionX != 0) || ((int)motionY != 0)) { moveImage(motionX, motionY); startX = e.X - motionX; startY = e.Y - motionY; } } else if (stateView == MODE_VIEW_ZOOMWINDOW) { HSystem.SetSystem("flush_graphic", "false"); ZoomWindow.ClearWindow(); posX = ((e.X - ImgCol1) / (ImgCol2 - ImgCol1)) * viewPort.Width; posY = ((e.Y - ImgRow1) / (ImgRow2 - ImgRow1)) * viewPort.Height; zoomZone = (zoomWndSize / 2) * zoomWndFactor * zoomAddOn; ZoomWindow.SetWindowExtents((int)posY - (zoomWndSize / 2), (int)posX - (zoomWndSize / 2), zoomWndSize, zoomWndSize); ZoomWindow.SetPart((int)(e.Y - zoomZone), (int)(e.X - zoomZone), (int)(e.Y + zoomZone), (int)(e.X + zoomZone)); repaint(ZoomWindow); HSystem.SetSystem("flush_graphic", "true"); ZoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0); } }
/*******************************************************************/ private void mouseUp(object sender, HalconDotNet.HMouseEventArgs e) { mousePressed = false; if (roiManager != null && (roiManager.activeROIidx != -1)) { roiManager.NotifyRCObserver(ROIController.EVENT_UPDATE_ROI); } }
private void mouseWheel(object sender, HalconDotNet.HMouseEventArgs e) { if (e.Delta > 0) { ScaleImage(e.X, e.Y, 0.9); } else { ScaleImage(e.X, e.Y, 1.1); } }
public void mouseWheel(object sender, HalconDotNet.HMouseEventArgs e) { if (e.Delta > 0) { zoomImage(e.X, e.Y, 0.9); } else { zoomImage(e.X, e.Y, 1.1); } }
/*************************************************************************/ /* Event handling for mouse */ /*************************************************************************/ private void mouseDown(object sender, HalconDotNet.HMouseEventArgs e) { _mousePressed = true; int activeROIidx = -1; double scale; if (_roiManager != null && (_dispROI == MODE_INCLUDE_ROI)) { activeROIidx = _roiManager.mouseDownAction(e.X, e.Y); } if (activeROIidx == -1) { switch (_stateView) { case MODE_VIEW_MOVE: _moveStartX = e.X; _moveStartY = e.Y; break; case MODE_VIEW_ZOOM: if (e.Button == System.Windows.Forms.MouseButtons.Left) { scale = 0.9; } else { scale = 1 / 0.9; } zoomImage(e.X, e.Y, scale); break; case MODE_VIEW_NONE: break; case MODE_VIEW_ZOOMWINDOW: activateZoomWindow((int)e.X, (int)e.Y); break; case MODE_VIEW_ZOOMCONTINUE: if (_roiManager != null && (_dispROI == MODE_INCLUDE_ROI)) { activeROIidx = _roiManager.mouseDownAction(e.X, e.Y); } break; default: break; } } //end of if }
private void HWindowControl0_HMouseUp(object sender, HalconDotNet.HMouseEventArgs e) { if (operaCross != null) { operaCross.Pixel = new PointF((float)e.X, (float)e.Y); crossCollection.Add(operaCross); operaCross = null; crossCollection.SetCrossActive(e.X, e.Y); Repaint(); } _mouseDown = false; }
private void HWindowControl0_HMouseMove(object sender, HalconDotNet.HMouseEventArgs e) { if (operaCross != null) { operaCross.Pixel = new PointF((float)e.X, (float)e.Y); Repaint(); } if (_mouseDown == true && e.Button == MouseButtons.Left && crossCollection.ActiveCross != null) { crossCollection.MoveActiveCross(e.X, e.Y); Repaint(); } }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mouseDown(object sender, HalconDotNet.HMouseEventArgs e) { //int tool_point = -1;//确定工具是否被选中 int button_state; double position_col_X, position_row_Y; _hWindowControl.HalconWindow.GetMpositionSubPix(out position_row_Y, out position_col_X, out button_state); /************确定有没有ROI被选中*************/ if (_roiControl.isArrayROIExit() == true) { _boolROIChioce = _roiControl.selectedROI(position_col_X, position_row_Y); } }
private void MouseDown(object sender, HalconDotNet.HMouseEventArgs e) { if (e.Button == MouseButtons.Left) { if ((Control.ModifierKeys & Keys.Control) == Keys.Control) { if (roiManager.ROIList.Count > 0) { var roi = Clone(roiManager.ROIList[roiManager.ROIList.Count - 1]); roiManager.CopyROIShape(roi as ROI, (double)e.X, (double)e.Y); } } } }
/*************************************************************************/ /* Event handling for mouse */ /*************************************************************************/ private void mouseDown(object sender, HalconDotNet.HMouseEventArgs e) { if (inMeasureLine) { return; } if (e.Button != MouseButtons.Left) { return; } if (isMouseFirstClick) { if (MouseDoubleClick != null) { MouseDoubleClick(this, new MouseEventArgs(e.Button, e.Clicks, (int)e.X, (int)e.Y, e.Delta)); } } if (isMouseFirstClick == false) { timeMouseDoubleClick.Start(); //200毫秒定时器 isMouseFirstClick = true; } mousePressed = true; int state; double x, y; try { viewPort.HalconWindow.GetMpositionSubPix(out y, out x, out state); } catch (HalconException) { return; } int activeROIidx = -1; if (roiManager != null && (showMode == ShowMode.IncludeROI)) { activeROIidx = roiManager.MouseDownAction(x, y); //由ROIController处理鼠标按下的事件。 } if (activeROIidx == -1) //表示鼠标按下没有激活ROI. { startX = x; //表示鼠标按下的当前X坐标,由其它鼠标响应事件来利用。 startY = y; } }
/*******************************************************************/ private void mouseUp(object sender, HalconDotNet.HMouseEventArgs e) { mousePressed = false; if (roiManager != null && (roiManager.activeROIidx != -1) && (dispROI == MODE_INCLUDE_ROI)) { roiManager.NotifyRCObserver(ROIController.EVENT_UPDATE_ROI); } else if (stateView == MODE_VIEW_ZOOMWINDOW) { ZoomWindow.Dispose(); } }
/*******************************************************************/ private void mouseUp(object sender, HalconDotNet.HMouseEventArgs e) { if (inMeasureLine) { return; } mousePressed = false; if (roiManager != null && (roiManager.ActiveRoiIdx != -1) && (showMode == ShowMode.IncludeROI)) { roiManager.TiggerROINotifyEvent(new ViewEventArgs(ViewMessage.UpdateROI)); } }
/// <summary> /// 連續放大鏡模式 Action /// </summary> /// <param name="e"></param> private void doZoomContinueAction(HalconDotNet.HMouseEventArgs e) { if (_enableZoomContinue) { activateZoomWindow((int)e.X, (int)e.Y); _enableZoomContinue = false; } if (ZoomWindow != null) { resetZoomWindow(e); ZoomWindow.SetColor("red"); ZoomWindow.DispCross(e.Y, e.X, 16.0, 0.785398); ZoomWindow.SetColor(this.ZoomWindowColor); } }
/*************************************************************************/ /* Event handling for mouse */ /*************************************************************************/ private void mouseDown(object sender, HalconDotNet.HMouseEventArgs e) { double num = (imageWidth) / ((double)this.viewPort.Size.Width); double num2 = (imageHeight) / ((double)this.viewPort.Size.Height); Location_points.Text = (string)((Math.Round((double)(e.X)) + ", " + Math.Round((double)(e.Y)))); // MessageBox.Show("x is " + (double)Convert.ToSingle(Math.Round((double)(e.Y * num2))) + "y is " + (double)Convert.ToSingle(Math.Round((double)(e.X * num)))); // this.MousePoint = new My_Point((double)Convert.ToSingle(Math.Round((double)(e.Y * num2))), (double)Convert.ToSingle(Math.Round((double)(e.X * num)))); //关闭缩放事件 if (drawModel) { return; } stateView = MODE_VIEW_MOVE; mousePressed = true; int activeROIidx = -1; if (roiManager != null && (dispROI == MODE_INCLUDE_ROI)) { activeROIidx = roiManager.mouseDownAction(e.X, e.Y); } if (activeROIidx == -1) { switch (stateView) { case MODE_VIEW_MOVE: startX = e.X; startY = e.Y; break; case MODE_VIEW_NONE: break; case MODE_VIEW_ZOOMWINDOW: activateZoomWindow((int)e.X, (int)e.Y); break; default: break; } } //end of if }
void GetActiveRoiParameters(object sender, HalconDotNet.HMouseEventArgs e) { var roi = RoiController.getActiveROI(); if (roi == null) { return; } dataGridView1.Rows.Clear(); dataGridView1.Rows.Add(roi.getModelDataName().Length); for (var i = 0; i < roi.getModelDataName().Length; i++) { dataGridView1.Rows[i].Cells[0].Value = roi.getModelDataName()[i].S; dataGridView1.Rows[i].Cells[1].Value = roi.getModelData()[i].D; } }
private void hWindowControl3_HMouseMove(object sender, HalconDotNet.HMouseEventArgs e) { HTuple Window = new HTuple(); Window = HalconWin3.HalconWindow; HTuple Row1, Col1, Button; try { HOperatorSet.GetMposition(Window, out Row1, out Col1, out Button); MStatusLblX.Text = Col1.ToString(); MStatusLblY.Text = Row1.ToString(); } catch { } }
/// <summary> /// 重置放大鏡視窗 /// </summary> /// <param name="e"></param> private void resetZoomWindow(HalconDotNet.HMouseEventArgs e) { HSystem.SetSystem("flush_graphic", "false"); ZoomWindow.ClearWindow(); double posX = ((e.X - ImgCol1) / (ImgCol2 - ImgCol1)) * _viewPort.Width; double posY = ((e.Y - ImgRow1) / (ImgRow2 - ImgRow1)) * _viewPort.Height; double zoomZone = (zoomWndSize / 2) * zoomWndFactor * zoomAddOn; ZoomWindow.SetWindowExtents((int)posY - (zoomWndSize / 2), (int)posX - (zoomWndSize / 2), zoomWndSize, zoomWndSize); ZoomWindow.SetPart((int)(e.Y - zoomZone), (int)(e.X - zoomZone), (int)(e.Y + zoomZone), (int)(e.X + zoomZone)); repaint(ZoomWindow); HSystem.SetSystem("flush_graphic", "true"); ZoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0); }
/*************************************************************************/ /* Event handling for mouse */ /*************************************************************************/ private void mouseWheeled(object sender, HalconDotNet.HMouseEventArgs e) { double scale; if (e.Delta < 0) { scale = 0.9; } else if (e.Delta > 0) { scale = 1 / 0.9; } else { scale = 1; } zoomImage(e.X, e.Y, scale); }
/*******************************************************************/ private void mouseMoved(object sender, HalconDotNet.HMouseEventArgs e) { double motionX, motionY; if (_stateView == MODE_VIEW_ZOOMCONTINUE) { doZoomContinueAction(e); return; } if (!_mousePressed) { return; } if (_roiManager != null && (_roiManager.activeROIidx != -1) && (_dispROI == MODE_INCLUDE_ROI)) { _roiManager.mouseMoveAction(e.X, e.Y); } else if (_stateView == MODE_VIEW_MOVE) { motionX = ((e.X - _moveStartX)); motionY = ((e.Y - _moveStartY)); if (((int)motionX != 0) || ((int)motionY != 0)) { moveImage(motionX, motionY); _moveStartX = e.X - motionX; _moveStartY = e.Y - motionY; } } else if (_stateView == MODE_VIEW_ZOOMWINDOW) { if (ZoomWindow != null) { resetZoomWindow(e); } } }
private void WindowFrame_DoubleClick(object sender, EventArgs e) { HMouseEventArgs e1 = (HMouseEventArgs)null; try { bool flag = false; MouseEventArgs e2 = (MouseEventArgs)e; this._last_position.X = e2.X; this._last_position.Y = e2.Y; if (e2.Button == MouseButtons.Left && this.InteractingWithDrawingObjs()) { double rowImage; double columnImage; this._hwindow.ConvertCoordinatesWindowToImage((double)this._last_position.Y, (double)this._last_position.X, out rowImage, out columnImage); flag = (HTuple)this._hwindow.SendMouseDoubleClickEvent((HTuple)rowImage, (HTuple)columnImage, this.MouseEventToInt(e2)) == true; } if (!flag && this.HDoubleClickToFitContent) { this.SetFullImagePart((HImage)null); } e1 = this.ToHMouse(e2); } catch (HalconException ex) { if (this.HErrorNotify != null) { this.HErrorNotify(ex); } } if (this.HMouseDoubleClick == null) { return; } this.HMouseDoubleClick((object)this, e1); }