C#Halcon联合编程动态生成显示窗口

发布于:2025-02-11 ⋅ 阅读:(44) ⋅ 点赞:(0)

UI编辑界面

.exe显示界面

代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HalconDotNet;

namespace Test HWindow 动态生成窗口
{
    public partial class Form1 : Form
    {
        //声明全局窗口变量
        List<ChoiceTech.Halcon.Control.HWindow_HE> hw = new 
        List<ChoiceTech.Halcon.Control.HWindow_HE>();

        ChoiceTech.Halcon.Control.HWindow_HE hw1 = new ChoiceTech.Halcon.Control.HWindow_HE() { Dock = DockStyle.Fill };
        ChoiceTech.Halcon.Control.HWindow_HE hw2 = new ChoiceTech.Halcon.Control.HWindow_HE() { Dock = DockStyle.Fill };
        TableLayoutPanel tableLayoutPanel;
        public Form1()
        {
            InitializeComponent();
            
        }
        /// <summary>
        /// 创建布局器
        /// </summary>
        /// <returns>返回TableLayoutPanel容器</returns>
        /// 
        public TableLayoutPanel CreateTableLayoutPanel(int column,int row)
        {
            //实例化布局器
            TableLayoutPanel tableLayoutPanel = new TableLayoutPanel();
            //设置布局器的行列数
            tableLayoutPanel.ColumnCount = column;
            tableLayoutPanel.RowCount = row;
            for (int i = 0; i < row; i++)
            {
                tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, (100 / row)));//百分比
            }
            for (int i = 0; i < column; i++)
            {
                tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, (100 / column)));
            }
            //设置为填充满的模式
            tableLayoutPanel.Dock = DockStyle.Fill;
            //返回布局器
            return tableLayoutPanel;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int CamCount = 2;
            //int CamCount = Convert.ToInt16(textBox1.Text);
            tableLayoutPanel = CreateTableLayoutPanel( CamCount,1);//?列?行
            //tableLayoutPanel  增加列 行
            tableLayoutPanel.Controls.Add(hw1,0,0);//列,行
            tableLayoutPanel.Controls.Add(hw2, 1, 0);

            //HOperatorSet.SetWindowParam(hw1.hWindowControl.HalconWindow, "background_color", "white");
            panel1.Controls.Add(tableLayoutPanel) ;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            HObject obj1 = new HObject();
            HOperatorSet.ReadImage(out obj1, @"E:\项目\电芯上料现场\3拉\20240410_v1.0_3L\20240411_v2.0_3L\315标定图\泡沫横1\2.bmp");
            hw1.HobjectToHimage(obj1);
            HObject obj2 = new HObject();
            HOperatorSet.ReadImage(out obj2, @"E:\项目\电芯上料现场\3拉\20240410_v1.0_3L\20240411_v2.0_3L\315标定图\泡沫横1\3.bmp");
            hw2.HobjectToHimage(obj2);
        }

    }
}


网站公告

今日签到

点亮在社区的每一天
去签到