使用上面的方法,出现矩形框位置移动问题,修改了一下:
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
private void HWindowControl1_MouseUP(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
mouse_event(0x8 | 0x10, 0, 0, 0, 0);
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
hWindowControl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.HWindowControl1_MouseUP);
hWindowControl1.Focus();
HOperatorSet.DrawRectangle1(hWindowControl1.HalconWindow, out ht_RectRow1, out ht_RectRow2, out ht_RectCol1, out ht_RectCol2);
HalconDotNet.HObject ho_RectRegion;
HalconDotNet.HOperatorSet.GenRectangle1(
out ho_RectRegion,
ht_RectRow1, ht_RectRow2, ht_RectCol1, ht_RectCol2);
HObject regionContour;
HOperatorSet.GenContourRegionXld(ho_RectRegion, out regionContour, "border");
HalconDotNet.HOperatorSet.DispObj(regionContour, hWindowControl1.HalconWindow);
hWindowControl1.MouseUp -= new System.Windows.Forms.MouseEventHandler(this.HWindowControl1_MouseUP);
}
catch (Exception)
{
}
} |