From ebcc1d53f14112363bbf539bcaf0202aadcdc9d7 Mon Sep 17 00:00:00 2001
From: C3032 <1057644574@qq.com>
Date: 星期一, 13 四月 2026 12:58:58 +0800
Subject: [PATCH] 2D取图计数功能完成
---
LB_VisionControl/UserHSmartWindowControl.cs | 59 +++++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/LB_VisionControl/UserHSmartWindowControl.cs b/LB_VisionControl/UserHSmartWindowControl.cs
index 6aae2eb..f91ead5 100644
--- a/LB_VisionControl/UserHSmartWindowControl.cs
+++ b/LB_VisionControl/UserHSmartWindowControl.cs
@@ -1,8 +1,12 @@
锘縰sing HalconDotNet;
+using Sunny.UI.Win32;
using System.Diagnostics;
+using System.Windows.Forms;
namespace LB_VisionControl
{
+ public delegate void Control_MouseDown(object sender, MouseEventArgs e);
+ public delegate void Control_MouseDoubleClick(object sender, MouseEventArgs e);
public partial class UserHSmartWindowControl : UserControl
{
public UserHSmartWindowControl()
@@ -18,7 +22,22 @@
// 璁剧疆榛樿瀛椾綋涓� 20鍙� mono瀛椾綋鍔犵矖
set_display_font(this.hWindowControl.HalconWindow, 20, "mono", "true", "false");
}
-
+ public event Control_MouseDown event_MouseDown;
+ public event Control_MouseDoubleClick event_MouseDoubleClick;
+ private void event_mouseDown(object sender, MouseEventArgs e)
+ {
+ if (event_MouseDown != null)
+ {
+ event_MouseDown(sender, e);
+ }
+ }
+ private void event_mouseDoubleClick(object sender, MouseEventArgs e)
+ {
+ if (event_MouseDoubleClick != null)
+ {
+ event_MouseDoubleClick(sender, e);
+ }
+ }
private void UserHSmartWindowControl_Load(object sender, EventArgs e)
{
// 鍚敤鍙岀紦鍐插噺灏戦棯鐑�
@@ -32,11 +51,11 @@
/// </summary>
public bool bAutoSize = true;
- private HImage _hImage = null;
+ private HObject _hImage = null;
/// <summary>
/// 鏄剧ず鍥剧墖(寮傛)
/// </summary>
- public HImage hImage
+ public HObject hImage
{
get
{
@@ -273,10 +292,10 @@
/// <param name="ho_image"></param>
/// <param name="hWindow"></param>
/// <param name="autoSize"></param>
- public async void ShowHoImageAsync(HImage ho_image, HWindow hWindow, bool autoSize = true)
+ public async void ShowHoImageAsync(HObject ho_image, HWindow hWindow, bool autoSize = true)
{
if (ho_image == null || !ho_image.IsInitialized())
- hWindow.ClearWindow();
+ HOperatorSet.ClearWindow(hWindow);
else
await ShowImageAsync(hWindow, ho_image, autoSize);
}
@@ -286,10 +305,10 @@
/// </summary>
/// <param name="ho_image"></param>
/// <param name="autoSize"></param>
- public void ShowHoImage(HImage ho_image, bool autoSize = true)
+ public void ShowHoImage(HObject ho_image, bool autoSize = true)
{
_hImage = ho_image;
- hWindowControl.HalconWindow.ClearWindow();
+ HOperatorSet.ClearWindow(hWindowControl.HalconWindow);
if (ho_image == null)
return;
@@ -343,7 +362,7 @@
return;
}
- private async Task<bool> ShowImageAsync(HWindow hWindow, HImage ho_image, bool autoSize = true)
+ private async Task<bool> ShowImageAsync(HWindow hWindow, HObject ho_image, bool autoSize = true)
{
return await Task.Run(() =>
{
@@ -351,7 +370,7 @@
{
try
{
- hWindow.ClearWindow();
+ HOperatorSet.ClearWindow(hWindow);
}
catch { return false; }
return true;
@@ -359,11 +378,11 @@
try
{
- hWindow.ClearWindow();
+ HOperatorSet.ClearWindow(hWindow);
if (autoSize)
{
- ho_image.GetImageSize(out HTuple imgWidth, out HTuple imgHeight);
+ HOperatorSet.GetImageSize(ho_image, out HTuple imgWidth, out HTuple imgHeight);
if (imgWidth.Length > 0)
{
hWindow.GetWindowExtents(out int winRow, out int winCol, out int winWidth, out int winHeight);
@@ -395,7 +414,7 @@
}
}
- hWindow.DispObj(ho_image);
+ HOperatorSet.DispObj(ho_image, hWindow);
}
catch { return false; }
return true;
@@ -421,7 +440,7 @@
try
{
if (ho_object != null && ho_object.IsInitialized())
- this.hWindowControl.HalconWindow.DispObj(ho_object);
+ HOperatorSet.DispObj(ho_object, this.hWindowControl.HalconWindow);
}
catch { }
}
@@ -433,7 +452,7 @@
if (ho_object != null && ho_object.IsInitialized())
{
SetColor(color);
- this.hWindowControl.HalconWindow.DispObj(ho_object);
+ HOperatorSet.DispObj(ho_object, this.hWindowControl.HalconWindow);
}
}
catch { }
@@ -447,7 +466,7 @@
{
string color = result ? "green" : "red";
SetColor(color);
- this.hWindowControl.HalconWindow.DispObj(ho_object);
+ HOperatorSet.DispObj(ho_object, this.hWindowControl.HalconWindow);
}
}
catch { }
@@ -488,7 +507,7 @@
if (this.color != color)
{
- this.hWindowControl.HalconWindow.SetColor( color);
+ HOperatorSet.SetColor(this.hWindowControl.HalconWindow, color);
this.color = color;
}
}
@@ -968,6 +987,8 @@
default:
break;
}
+ MouseEventArgs mouseEventArgs = new MouseEventArgs(e.Button, e.Clicks, (int)e.X, (int)e.Y, e.Delta);
+ event_mouseDown(sender, mouseEventArgs);
}
catch { }
}
@@ -1170,5 +1191,11 @@
{
ShowHoImage(hImage);
}
+
+ private void hWindowControl_HMouseDoubleClick(object sender, HMouseEventArgs e)
+ {
+ MouseEventArgs mouseEventArgs = new MouseEventArgs(e.Button, e.Clicks, (int)e.X, (int)e.Y, e.Delta);
+ event_mouseDoubleClick(sender, mouseEventArgs);
+ }
}
}
--
Gitblit v1.9.3