//窗体所需参数
private HTuple mouseDowmRowLT1, mouseDownColLT1, mouseDownRowLT2, mouseDownColLT2;
private HTuple currentRowLT1, currentColLT1, currentRowLT2, currentColLT2;
// 鼠标指针坐标值及对应像素点的灰度值
private HTuple mouseDownPosRowLT, mouseDownPosColLT;
private HTuple currentPosRowLT, currentPosColLT;//, currentGrayValLT;
private Point mouseDownPointLT;// 记录鼠标按下时的点
private bool isMouseDownLT = false; // 鼠标左键是否按下
public static HObject ho_ImageLT; // 当前图像
public static HObject ho_ImageLTLable;//带结果图
public bool MouseFalseLT = false;//鼠标是否按下标志
private bool HalconWindowbigLT = false;//窗体是否放大标志
private int countLT = 0;//点击鼠标计数
Stopwatch timeDoubleLT = new Stopwatch();//双击鼠标计时
//鼠标单击事件
private void hWindowControlLT_HMouseDown(object sender, HMouseEventArgs e)
{
HObject ho_emptyObject;
HTuple isEqualLT, hv_Width, hv_Height, button;
//判断是否有图片
(out ho_emptyObject);
(ho_emptyObject, ho_ImageLT, out isEqualLT);
if (isEqualLT == true) return;
//鼠标左键,记录当前位置及显示图像的部分
if ( == )
{
if (countLT == 0) //鼠标第一次按下
{
countLT = 1;
();
();
(, out mouseDowmRowLT1, out mouseDownColLT1, out mouseDownRowLT2, out mouseDownColLT2);
(, out mouseDownPosRowLT, out mouseDownPosColLT, out button);
= ;
= ;
isMouseDownLT = true;
}
else if (countLT == 1)//鼠标第二次按下
{
();
if ( < 300)//双击鼠标间隔
{
if (HalconWindowbigLT == false)//准备放大窗体
{
(hWindowControlLT, 0, 0);
(hWindowControlLT, 3);
(hWindowControlLT, 3);
HalconWindowbigLT = true;
}
else //准备缩小窗体
{
(hWindowControlLT, 0, 0);
(hWindowControlLT, 1);
(hWindowControlLT, 1);
HalconWindowbigLT = false;
}
}
countLT = 0;
}
}
else if ( == ) //右击--自适应窗体
{
(ho_ImageLT, out hv_Width, out hv_Height);
DispImageLT(hWindowControlLT, hv_Width, hv_Height);
(ho_ImageLT, );
}
}
//鼠标移动事件-----图片跟着鼠标移动
private void hWindowControlLT_HMouseMove(object sender, HMouseEventArgs e)
{
HObject ho_emptyObject;
HTuple isEqualLT, button;
//判断是否有图片
(out ho_emptyObject);
(ho_emptyObject, ho_ImageLT, out isEqualLT);
if (isEqualLT == true) return;
//if (ho_ImageLT == null) return;
if (isMouseDownLT) //鼠标按下拖动图像移动
{ (, out currentPosRowLT, out currentPosColLT, out button);
double rowMove = currentPosRowLT - mouseDownPosRowLT;
double colMove = currentPosColLT - mouseDownPosColLT;
(, out currentRowLT1, out currentColLT1, out currentRowLT2, out currentColLT2);
(, currentRowLT1 - rowMove, currentColLT1 - colMove, currentRowLT2 - rowMove, currentColLT2 - colMove);
();
(ho_ImageLT, );
}
//else //实时显示像素坐标及灰度值
//{
// getPosAndGrayVal(out currentPosRow, out currentPosCol, out currentGrayVal);
// = "坐标:(" + () + "," + () + ")";
// = "值:" + ();
//}
}
//鼠标松开事件
private void hWindowControlLT_HMouseUp(object sender, HMouseEventArgs e)
{
isMouseDownLT = false;
}
// 图像以鼠标指针所指位置为中心缩放
private void hWindowControlLT_HMouseWheel(object sender, HMouseEventArgs e)
{
HObject ho_emptyObject;
HTuple isEqualLT, button;
(out ho_emptyObject);
(ho_emptyObject, ho_ImageLT, out isEqualLT);
if (isEqualLT == true) return;
//if (ho_ImageLT == null) return;
(, out currentPosRowLT, out currentPosColLT, out button);
(, out currentRowLT1, out currentColLT1, out currentRowLT2, out currentColLT2);
double rowMove1 = (currentRowLT1 - currentPosRowLT) * 0.2;
double colMove1 = (currentColLT1 - currentPosColLT) * 0.2;
double rowMove2 = (currentRowLT2 - currentPosRowLT) * 0.2;
double colMove2 = (currentColLT2 - currentPosColLT) * 0.2;
if ( > 0)
{
(, currentRowLT1 + rowMove1, currentColLT1 + colMove1, currentRowLT2 + rowMove2, currentColLT2 + colMove2);
}
else if ( < 0)
{
(, currentRowLT1 - rowMove1, currentColLT1 - colMove1, currentRowLT2 - rowMove2, currentColLT2 - colMove2);
}
();
(ho_ImageLT, );
}