一直想达到这个效果,奈何智商简单;今天来做一下记录;
个人习惯 Winform 新建以后删除xxx.designer.cs再双击Form1.cs设计器;就会在该 文件下
自动生成InitializeComponent() 且可 由设计器生成的所有winform界面程序则会出现在InitializeComponent()里面;
这样的好处很多,所有设计器的操作都可以以单一文件程序的方式呈现在面前
想要一个这样的功能:
可以自适应图片缩放在不同图像宽高比和窗口宽高比 的 情况下 保证图像完整显示并居中
缩放的同时绘制ROI ROI可以记录 位置下次修改 可以存储ROI位置 存储 ROI抠的图
算了 虽然这个不完善: 但最近流行一句话 一个粗糙的开始就是最好的开始.
算了算了 上程序.
using HalconDotNet;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.CodeDom;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Media.Media3D;
namespace hsmart
{
public partial class Form1 : Form
{
private Button button1;
private Button button2;
private Label label1;
private Button button3;
private HalconDotNet.HSmartWindowControl hSmartWindowControl1;
HWindow hwindow;
private Button button4;
private Button button5;
string Getcwd = System.Environment.CurrentDirectory;
private Sunisoft.IrisSkin.SkinEngine skinEngine1;// MacOS 风格
private bool 黑魔法_Load(string S= "MacOS")// 应用
{
// skinEngine1
this.skinEngine1 = new Sunisoft.IrisSkin.SkinEngine(); // MacOS
this.skinEngine1.@__DrawButtonFocusRectangle = true;
this.skinEngine1.DisabledButtonTextColor = System.Drawing.Color.Gray;
this.skinEngine1.DisabledMenuFontColor = System.Drawing.SystemColors.GrayText;
this.skinEngine1.InactiveCaptionColor = System.Drawing.SystemColors.InactiveCaptionText;
this.skinEngine1.SerialNumber = "";
this.skinEngine1.SkinFile = null;
skinEngine1.SkinFile = System.Environment.CurrentDirectory + $@"\Skins\{S}.ssk";
return true;
}
public Form1()
{
InitializeComponent();
黑魔法_Load();
displayResult_Load();
hwindow = hSmartWindowControl1.HalconWindow;//从初始化窗口变量
}
private void InitializeComponent()
{
this.hSmartWindowControl1 = new HalconDotNet.HSmartWindowControl();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// hSmartWindowControl1
//
this.hSmartWindowControl1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.hSmartWindowControl1.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange;
this.hSmartWindowControl1.HDoubleClickToFitContent = true;
this.hSmartWindowControl1.HDrawingObjectsModifier = HalconDotNet.HSmartWindowControl.DrawingObjectsModifier.None;
this.hSmartWindowControl1.HImagePart = new System.Drawing.Rectangle(0, 0, 640, 480);
this.hSmartWindowControl1.HKeepAspectRatio = true;
this.hSmartWindowControl1.HMoveContent = true;
this.hSmartWindowControl1.HZoomContent = HalconDotNet.HSmartWindowControl.ZoomContent.WheelForwardZoomsIn;
this.hSmartWindowControl1.Location = new System.Drawing.Point(232, 61);
this.hSmartWindowControl1.Margin = new System.Windows.Forms.Padding(0);
t