C#与Halcon联合(10)通过外部函数在halcon窗体上写字

1.halcon12 相关写字算子

*设置字体大小,类型,粗体,斜体
set_display_font (3600, 16, 'mono', 'true', 'false')
*设置  显示内容,显示的坐标系,行列, 字体颜色, 背景
disp_message (3600,'Hello World!' , 'window', 12, 12, 'black', 'true')

鼠标移至算子按住f1可以查看详细信息可以

set_display_font

Size : 字体的大小,建议值: [9, 11, 14, 16, 20, 27]
Font :字体类型,建议值: ‘mono’, ‘sans’, ‘serif’
Bold : 粗体,true文字加粗,false不加粗
Slant : 斜体,true文字倾斜,false不倾斜

disp_message

String :显示内容
CoordSystem:依赖坐标系window 还是 image
选择window就是以窗体左上为(0,0),选择image则是图像左上为(0,0)
Row :行,在CoordSystem的原点的基础上偏移
Column:列,在CoordSystem的原点的基础上偏移
Color :字体颜色
Box :是否显示背景

2.如何查看外部函数的内容

①鼠标移至算子右键选择【在新窗口中显示】

在这里插入图片描述

②直接导出为C#文件查看

在这里插入图片描述

3.C#联合Halcon外部函数在窗体显示文字

①页面设计如下

在这里插入图片描述

②工程构造

在这里插入图片描述

③相关代码

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 WriteStrToHalcon
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        HalconView m_Wnd = new HalconView();//halcon窗体
        HTuple size, font, bold, slant, str, coordSystem, row, col, color, box;

        private void button2_Click(object sender, EventArgs e)
        {
            m_Wnd.HalconWindow.ClearWindow();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UpdateUi(true);
            HalconView.set_display_font(m_Wnd.HalconWindow,size,font,bold,slant);
            HalconView.disp_message(m_Wnd.HalconWindow, str, coordSystem, row, col, color, box);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.panel1.Controls.Add(m_Wnd);
            m_Wnd.Dock = DockStyle.Fill;
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
            comboBox3.SelectedIndex = 0;
        }

        public void UpdateUi(bool bUpdate)
        {
            if (bUpdate)
            {
                 size = (int)numericUpDown1.Value;//字体大小
                 font = comboBox1.SelectedItem.ToString();//字体类型
                 bold = checkBox1.Checked ? "true" : "false";//粗体
                 slant = checkBox2.Checked ? "true" : "false";//斜体
                 str = textBox1.Text;//显示内容
                 coordSystem = comboBox2.SelectedItem.ToString();//原点依赖
                 row = (int)numericUpDown2.Value;//行
                 col = (int)numericUpDown3.Value;//列
                 color = comboBox3.SelectedItem.ToString();//字体颜色
                 box = checkBox3.Checked ? "true" : "false";//背景框
            }
            else
            {

            }
        }
    }
}

4.代码下载

https://download.csdn.net/download/adsd1233123/85151958

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱搞事的程小猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值