《Sherlock联合C#》7.ROI缩放,打开参数界面

定义变量

Sherlock显示控件鼠标移动事件

Sherlock显示控件鼠标左键按下事件

Sherlock显示控件鼠标左键抬起事件

在窗口Form的MouseMove事件应当设置默认光标

实际程序

 private void Cam1_MouseMoveEvent(object sender, AxIpeDspCtrlLib._DIpeDspCtrlEvents_MouseMoveEvent e)
        {
            sherlock.RoiGetNames("imgA",out Roinames);                       //获取在imgA窗口下所有的ROI名称集合,注:imgA为()内参数,可以改变。
            Roiname=(string)Roinames.GetValue(0);                            //获取ROI名称集合的第一个ROI名称,即Roiname               
            sherlock.RoiCoordArrayGet(Roiname, out CoordsX, out CoordsY);    //获取Roiname的定义坐标,矩形ROI为左上点和右下点    
            sherlock.RoiSelectedSet(Roiname, 1);                             //显示ROI的各个点
            sherlock.VarGetDouble("CamW", out CamW);
            sherlock.VarGetDouble("CamH", out CamH);
            sherlock.RoiTypeGet(Roiname, out RoiType);                       //获取Roiname的ROI类型    
           
            if (RoiType == "RoiRect")
            {
                if (e.x > ((int)CoordsX.GetValue(0) + 10) && e.x < ((int)CoordsX.GetValue(1) - 10) && (e.y > (int)CoordsY.GetValue(0) + 10) && (e.y < (int)CoordsY.GetValue(1) - 10))
                    this.Cursor = Cursors.SizeAll;                               //移动              

                if (e.x > ((int)CoordsX.GetValue(0) - 10) && e.x < ((int)CoordsX.GetValue(0) + 10) && (e.y > (int)CoordsY.GetValue(0) - 10) && (e.y < (int)CoordsY.GetValue(0) + 10))
                    this.Cursor = Cursors.SizeNWSE;                              //缩放  左上点

                if (e.x > ((int)CoordsX.GetValue(0) - 10) && e.x < ((int)CoordsX.GetValue(0) + 10) && (e.y > (int)CoordsY.GetValue(1) - 10) && (e.y < (int)CoordsY.GetValue(1) + 10))
                    this.Cursor = Cursors.SizeNESW;                              //缩放  左下点               

                if (e.x > ((int)CoordsX.GetValue(1) - 10) && e.x < ((int)CoordsX.GetValue(1) + 10) && (e.y > (int)CoordsY.GetValue(0) - 10) && (e.y < (int)CoordsY.GetValue(0) + 10))
                    this.Cursor = Cursors.SizeNESW;                              //缩放  右上点

                if (e.x > ((int)CoordsX.GetValue(1) - 10) && e.x < ((int)CoordsX.GetValue(1) + 10) && (e.y > (int)CoordsY.GetValue(1) - 10) && (e.y < (int)CoordsY.GetValue(1) + 10))
                    this.Cursor = Cursors.SizeNWSE;                              //缩放  右下点

                if (e.x > ((int)CoordsX.GetValue(0) - 10) && e.x < ((int)CoordsX.GetValue(0) + 10) && (e.y > (int)CoordsY.GetValue(0) + 10) && (e.y < (int)CoordsY.GetValue(1) - 10))
                    this.Cursor = Cursors.SizeWE;                                //缩放  左边

                if (e.x > ((int)CoordsX.GetValue(1) - 10) && e.x < ((int)CoordsX.GetValue(1) + 10) && (e.y > (int)CoordsY.GetValue(0) + 10) && (e.y < (int)CoordsY.GetValue(1) - 10))
                    this.Cursor = Cursors.SizeWE;                                //缩放  右边

                if (e.x > ((int)CoordsX.GetValue(0) + 10) && e.x < ((int)CoordsX.GetValue(1) - 10) && (e.y > (int)CoordsY.GetValue(0) - 10) && (e.y < (int)CoordsY.GetValue(0) + 10))
                    this.Cursor = Cursors.SizeNS;                                //缩放  上边

                if (e.x > ((int)CoordsX.GetValue(0) + 10) && e.x < ((int)CoordsX.GetValue(1) - 10) && (e.y > (int)CoordsY.GetValue(1) - 10) && (e.y < (int)CoordsY.GetValue(1) + 10))
                    this.Cursor = Cursors.SizeNS;                                //缩放  下边

                if (bmrect)
                {
                    sherlock.RoiMove(Roiname, e.x - pointx, e.y - pointy);
                    pointx = e.x;
                    pointy = e.y;
                }
                if (bsrect1)
                {
                    CoordsX.SetValue(e.x, 0);
                    CoordsY.SetValue(e.y, 0);
                    sherlock.RoiCoordArraySet(Roiname, CoordsX, CoordsY);
                }
                if (bsrect2)
                {
                    CoordsX.SetValue(e.x, 0);
                    CoordsY.SetValue(e.y, 1);
                    sherlock.RoiCoordArraySet(Roiname, CoordsX, CoordsY);
                }
                if (bsrect3)
                {
                    CoordsX.SetValue(e.x, 1);
                    CoordsY.SetValue(e.y, 0);
                    sherlock.RoiCoordArraySet(Roiname, CoordsX, CoordsY);
                }
                if (bsrect4)
                {
                    CoordsX.SetValue(e.x, 1);
                    CoordsY.SetValue(e.y, 1);
                    sherlock.RoiCoordArraySet(Roiname, CoordsX, CoordsY);
                }
                if (bsrect5)
                {
                    CoordsX.SetValue(e.x, 0);

                    sherlock.RoiCoordArraySet(Roiname, CoordsX, CoordsY);
                }
                if (bsrect6)
                {
                    CoordsX.SetValue(e.x, 1);

                    sherlock.RoiCoordArraySet(Roiname, CoordsX, CoordsY);
                }
                if (bsrect7)
                {

                    CoordsY.SetValue(e.y, 0);
                    sherlock.RoiCoordArraySet(Roiname, CoordsX, CoordsY);
                }
                if (bsrect8)
                {

                    CoordsY.SetValue(e.y, 1);
                    sherlock.RoiCoordArraySet(Roiname, CoordsX, CoordsY);
                }
               
                Cam1.Refresh();
            }
        }

          private void Cam1_LButtonDown(object sender, AxIpeDspCtrlLib._DIpeDspCtrlEvents_LButtonDownEvent e)
       {
           if (e.x > ((int)CoordsX.GetValue(0) + 10) && e.x < ((int)CoordsX.GetValue(1) - 10) && (e.y > (int)CoordsY.GetValue(0) + 10) && (e.y < (int)CoordsY.GetValue(1) - 10))
               bmrect = true;                                 //移动

           if (e.x > ((int)CoordsX.GetValue(0) - 10) && e.x < ((int)CoordsX.GetValue(0) + 10) && (e.y > (int)CoordsY.GetValue(0) - 10) && (e.y < (int)CoordsY.GetValue(0) + 10))
               bsrect1 = true;                                //缩放  左上点

           if (e.x > ((int)CoordsX.GetValue(0) - 10) && e.x < ((int)CoordsX.GetValue(0) + 10) && (e.y > (int)CoordsY.GetValue(1) - 10) && (e.y < (int)CoordsY.GetValue(1) + 10))
               bsrect2 = true;                                //缩放  左下点

           if (e.x > ((int)CoordsX.GetValue(1) - 10) && e.x < ((int)CoordsX.GetValue(1) + 10) && (e.y > (int)CoordsY.GetValue(0) - 10) && (e.y < (int)CoordsY.GetValue(0) + 10))
               bsrect3 = true;                                //缩放  右上点

           if (e.x > ((int)CoordsX.GetValue(1) - 10) && e.x < ((int)CoordsX.GetValue(1) + 10) && (e.y > (int)CoordsY.GetValue(1) - 10) && (e.y < (int)CoordsY.GetValue(1) + 10))
               bsrect4 = true;                               //缩放  右下点

           if (e.x > ((int)CoordsX.GetValue(0) - 10) && e.x < ((int)CoordsX.GetValue(0) + 10) && (e.y > (int)CoordsY.GetValue(0) + 10) && (e.y < (int)CoordsY.GetValue(1) - 10))
               bsrect5 = true;                               //缩放  左边

           if (e.x > ((int)CoordsX.GetValue(1) - 10) && e.x < ((int)CoordsX.GetValue(1) + 10) && (e.y > (int)CoordsY.GetValue(0) + 10) && (e.y < (int)CoordsY.GetValue(1) - 10))
               bsrect6 = true;                               //缩放  右边

           if (e.x > ((int)CoordsX.GetValue(0) + 10) && e.x < ((int)CoordsX.GetValue(1) - 10) && (e.y > (int)CoordsY.GetValue(0) - 10) && (e.y < (int)CoordsY.GetValue(0) + 10))
               bsrect7 = true;                               //缩放  上边

           if (e.x > ((int)CoordsX.GetValue(0) + 10) && e.x < ((int)CoordsX.GetValue(1) - 10) && (e.y > (int)CoordsY.GetValue(1) - 10) && (e.y < (int)CoordsY.GetValue(1) + 10))
               bsrect8 = true;                               //缩放  下边  
               
           pointx = e.x;                                     //光标当前坐标x值
           pointy = e.y;                                     //光标当前坐标x值
           
       }

          private void Cam1_LButtonUp(object sender, AxIpeDspCtrlLib._DIpeDspCtrlEvents_LButtonUpEvent e)
        {
            sherlock.RoiCoordArrayGet(Roiname, out CoordsX, out CoordsY);
            bmrect = false;
            bsrect1 = false;
            bsrect2 = false;
            bsrect3 = false;
            bsrect4 = false;
            bsrect5 = false;
            bsrect6 = false;
            bsrect7 = false;
            bsrect8 = false;
          
        }

          private void Cam1_LButtonDblClk(object sender, AxIpeDspCtrlLib._DIpeDspCtrlEvents_LButtonDblClkEvent e)
        {
            if (e.x > ((int)CoordsX.GetValue(0) + 10) && e.x < ((int)CoordsX.GetValue(1) - 10) && (e.y > (int)CoordsY.GetValue(0) + 10) && (e.y < (int)CoordsY.GetValue(1) - 10))
            {
                sherlock.InstrCommand(Roiname + ".Grayscale OCR", (int)IpeEngCtrlLib.I_INSTR_COMMANDS.INSTR_SHOW_PARMS_DLG, 0);
            }

        }

          private void Form1_MouseMove(object sender, MouseEventArgs e)
          {
              this.Cursor = Cursors.Default;
          }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值