C# Visionpro 主窗体调用子窗体(自定义控件)按照行列进行显示(双击子窗体全窗口显示)

server/2024/12/18 18:39:59/

自定义控件界面及控件如下

控件列表

using Cognex.VisionPro;
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 Cognex.VisionPro.ToolBlock;
using Cognex.VisionPro.ToolGroup;
using System.Security.RightsManagement;
using System.Windows.Forms.VisualStyles;

namespace VMPro2024._08.UserControl8
{
public partial class DisplayControl : UserControl
{
#region 申明变量
public DisplayControl displayControl;
public TitleForm titleForm;
#endregion

    DisplayControl _displayControl;public DisplayControl(){InitializeComponent();this.displayControl = _displayControl;           }public void IniDisplay(){this.cogDisplayStatusBarV21.Display = this.cogRecordDisplay1;this.cogDisplayToolbarV21.Display = this.cogRecordDisplay1;this.cogRecordDisplay1.AutoFit = true;}//toolstrippublic CogRecordDisplay cogRecordDisplay{set { this.cogRecordDisplay1 = value; }get { return this.cogRecordDisplay1; }}#region 实时采集图像/// <summary>/// 第一个窗体中的toolstrip事件/// </summary>public ToolStripStatusLabel toolStripStatusLabel1{get{return this.相机实时_toolStripLabel;}}/// <summary>/// 第二个窗体中的toolstrip事件/// </summary>public ToolStripStatusLabel toolStripStatusLabel2{get{return this.相机实时_toolStripLabel;}}/// <summary>/// 第三个窗体中的toolstrip事件/// </summary>public ToolStripStatusLabel toolStripStatusLabel3{get{return this.相机实时_toolStripLabel;}}/// <summary>/// 第四个窗体中的toolstrip事件/// </summary>public ToolStripStatusLabel toolStripStatusLabel4{get{return this.相机实时_toolStripLabel;}}/// <summary>/// 第五个窗体中的toolstrip事件/// </summary>public ToolStripStatusLabel toolStripStatusLabel5{get{return this.相机实时_toolStripLabel;}}/// <summary>/// 第六个窗体中的toolstrip事件/// </summary>public ToolStripStatusLabel toolStripStatusLabel6{get{return this.相机实时_toolStripLabel;}}#endregion#region 相机单次采图/// <summary>/// 第一个子窗体手动拍照按钮/// </summary>public ToolStripStatusLabel toolStripStatusLabel拍照1{get{return this.相机拍照_toolStatusLabel;}}/// <summary>/// 第二个子窗体手动拍照按钮/// </summary>public ToolStripStatusLabel toolStripStatusLabel拍照2{get{return this.相机拍照_toolStatusLabel;}}/// <summary>/// 第三个子窗体手动拍照按钮/// </summary>public ToolStripStatusLabel toolStripStatusLabel拍照3{get{return this.相机拍照_toolStatusLabel;}}/// <summary>/// 第四个子窗体手动拍照按钮/// </summary>public ToolStripStatusLabel toolStripStatusLabel拍照4{get{return this.相机拍照_toolStatusLabel;}}/// <summary>/// 第五个子窗体手动拍照按钮/// </summary>public ToolStripStatusLabel toolStripStatusLabel拍照5{get{return this.相机拍照_toolStatusLabel;}}/// <summary>/// 第六个子窗体手动拍照按钮/// </summary>public ToolStripStatusLabel toolStripStatusLabel拍照6{get{return this.相机拍照_toolStatusLabel;}}#endregion#region 放大缩小/// <summary>/// 放大/// </summary>public ToolStripDropDownButton 放大Button1{get{return this.放大Button;}}public ToolStripDropDownButton 缩小Button1{get{return this.缩小Button;}}#endregion}

}

窗体设置按钮调用另一个子窗体截图及代码,本窗体是3行2列!

控件:

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;

namespace VMPro2024._08.WinForm
{
public partial class WindFormSetting : Form
{
private int _row;

    public int cameraCount = 0;public int camerrow = 0;//public int cameraCount = 0; public int Row{get { return _row; }set { _row = value; }}private int _column;public int Column{get { return _column; }set { _column = value; }}public WindFormSetting(int row, int column, Form parent){this.Row = row;this.Column = column;InitializeComponent();this.StartPosition = FormStartPosition.Manual;this.Location = new Point(parent.Location.X + (parent.Size.Width / 2) - (this.Size.Width / 2),parent.Location.Y + (parent.Size.Height / 2) - (this.Size.Height));this.btnSetting.Click += new EventHandler(btnSetting_Click);//numRow = new NumericUpDown();//numColumn = new NumericUpDown();//mCamerCount(cameraCount);}public WindFormSetting(){}private void WindFormSetting_Load(object sender, EventArgs e){this.numRow.Value = this.Row;this.numColumn.Value = this.Column;}private void btnSetting_Click(object sender, EventArgs e){this.Row = Convert.ToInt32(this.numRow.Value);this.Column = Convert.ToInt32(this.numColumn.Value);this.Close();}/// <summary>/// 计算相机个数/// </summary>/// <param name="count"></param>//public int mCamerCount(int count)//{//用于计算相机个数//camerrow = Convert.ToInt32(this.numRow.Value);//camercolumn = Convert.ToInt32(this.numColumn.Value);//cameraCount = camerrow * camercolumn;//计算相机个数//return cameraCount;//}//设置行private void numRow_MouseDown(object sender, MouseEventArgs e){if (this.numRow.Value <= 3){this.numRow.Value++;}}private void numRow_MouseUp(object sender, MouseEventArgs e){if (this.numRow.Value >= 2){this.numRow.Value--;}}//设置列private void numColumn_MouseDown(object sender, MouseEventArgs e){if (this.numColumn.Value <= 4){this.numColumn.Value++;}}private void numColumn_MouseUp(object sender, MouseEventArgs e){if (this.numColumn.Value >= 2){this.numColumn.Value--;}}
}

}

主窗体

主窗体代码:

#region 窗体个数变量
public DisplayControl[] displayControls = new DisplayControl[10];//显示控件
bool bEnlarge = false;//判断是否双击激活 cogRecordDisplay_DoubleClick事件
#endregion
//设置窗体个数
private void 窗体设置ToolStripMenuItem_Click(object sender, EventArgs e)
{
WindFormSetting windFormSetting = new WindFormSetting(WindowConfig.gOnly.displayRow, WindowConfig.gOnly.displayColumn, this);
windFormSetting.ShowDialog();
DialogResult result = MessageBox.Show(“是否重设显示个数”, “选择按钮”, MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
WindowConfig.gOnly.displayRow = windFormSetting.Row;
WindowConfig.gOnly.displayColumn = windFormSetting.Column;
WindowConfig.SaveConfig();
//需要添加窗体修改Log

    IniDisplayCount(windFormSetting.Row, windFormSetting.Column, true);LoadConfigXml(cameraCount);//计算相机个数WindowConfig.gOnly.cameraCount = Convert.ToInt32(cameraCount);//存储相机个数MessageBox.Show(cameraCount.ToString());
}
windFormSetting.Dispose();//窗体销毁

}

//初始化窗口 设置tableLayoutPanel的相关属性
private void IniDisplayCount(int RowCount, int ColumnCount, bool bChange)
{
int displayCount = 0;
tableLayoutPanel2.RowStyles.Clear();
tableLayoutPanel2.ColumnStyles.Clear();
tableLayoutPanel2.RowCount = RowCount;
tableLayoutPanel2.ColumnCount = ColumnCount;

for (int i = 0; i < tableLayoutPanel2.RowCount; i++)
{tableLayoutPanel2.RowStyles.Add(new ColumnStyle(SizeType.Percent, 50));
}for (int i = 0; i < tableLayoutPanel2.ColumnCount; i++)
{tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
}if (bChange)
{for (int i = 0; i < displayControls.Length; i++){if (displayControls[i] != null){if (i == 0)displayControls[i].cogRecordDisplay.DoubleClick -= cogRecordDisplay1_DoubleClick;if (i == 1)displayControls[i].cogRecordDisplay.DoubleClick -= cogRecordDisplay2_DoubleClick;if (i == 2)displayControls[i].cogRecordDisplay.DoubleClick -= cogRecordDisplay3_DoubleClick;if (i == 3)displayControls[i].cogRecordDisplay.DoubleClick -= cogRecordDisplay4_DoubleClick;if (i == 4)displayControls[i].cogRecordDisplay.DoubleClick -= cogRecordDisplay5_DoubleClick;if (i == 5)displayControls[i].cogRecordDisplay.DoubleClick -= cogRecordDisplay6_DoubleClick;displayControls[i].Dispose();displayControls[i] = null;}}
}
for (int i = 0; i < RowCount; i++)
{for (int j = 0; j < ColumnCount; j++){displayControls[displayCount] = new DisplayControl();displayControls[displayCount].IniDisplay();displayControls[displayCount].Dock = DockStyle.Fill;tableLayoutPanel2.Controls.Add(displayControls[displayCount], j, i);if (i == 0 && j == 0)displayControls[displayCount].cogRecordDisplay.DoubleClick += cogRecordDisplay1_DoubleClick;if (i == 0 && j == 1)displayControls[displayCount].cogRecordDisplay.DoubleClick += cogRecordDisplay2_DoubleClick;if (i == 1 && j == 0)displayControls[displayCount].cogRecordDisplay.DoubleClick += cogRecordDisplay3_DoubleClick;if (i == 1 && j == 1)displayControls[displayCount].cogRecordDisplay.DoubleClick += cogRecordDisplay4_DoubleClick;if (i == 2 && j == 0)displayControls[displayCount].cogRecordDisplay.DoubleClick += cogRecordDisplay5_DoubleClick;if (i == 2 && j == 1)displayControls[displayCount].cogRecordDisplay.DoubleClick += cogRecordDisplay6_DoubleClick;displayCount++;}
}

}

#region 双击全窗口显示 恢复
private void cogRecordDisplay1_DoubleClick(object sender, EventArgs e)
{
Cognex.VisionPro.CogRecordDisplay recordDisplay = sender as Cognex.VisionPro.CogRecordDisplay;
if (bEnlarge)
{
//再次双击鼠标恢复
bEnlarge = false;

    tableLayoutPanel2.Controls.Add(displayControls[0]);displayControls[0].SendToBack();displayControls[0].Parent = tableLayoutPanel2;displayControls[0].Dock = DockStyle.Fill;tableLayoutPanel2.Show();
}
else
{//双击鼠标放大bEnlarge = true;tableLayoutPanel2.Controls.Remove(displayControls[0]);displayControls[0].Parent = this;displayControls[0].BringToFront();displayControls[0].Dock = DockStyle.Fill;tableLayoutPanel2.Hide();
}

}

private void cogRecordDisplay2_DoubleClick(object sender, EventArgs e)
{
Cognex.VisionPro.CogRecordDisplay recordDisplay = sender as Cognex.VisionPro.CogRecordDisplay;
if (bEnlarge)
{
//再次双击鼠标恢复
bEnlarge = false;

    tableLayoutPanel2.Controls.Add(displayControls[1]);displayControls[1].SendToBack();displayControls[1].Parent = tableLayoutPanel2;displayControls[1].Dock = DockStyle.Fill;tableLayoutPanel2.Show();
}
else
{//双击鼠标放大bEnlarge = true;tableLayoutPanel2.Controls.Remove(displayControls[1]);displayControls[1].Parent = this;displayControls[1].BringToFront();displayControls[1].Dock = DockStyle.Fill;tableLayoutPanel2.Hide();
}

}

private void cogRecordDisplay3_DoubleClick(object sender, EventArgs e)
{
Cognex.VisionPro.CogRecordDisplay recordDisplay = sender as Cognex.VisionPro.CogRecordDisplay;
if (bEnlarge)
{
//再次双击鼠标恢复
bEnlarge = false;

    tableLayoutPanel2.Controls.Add(displayControls[2]);displayControls[2].SendToBack();displayControls[2].Parent = tableLayoutPanel2;displayControls[2].Dock = DockStyle.Fill;tableLayoutPanel2.Show();
}
else
{//双击鼠标放大bEnlarge = true;tableLayoutPanel2.Controls.Remove(displayControls[2]);displayControls[2].Parent = this;displayControls[2].BringToFront();displayControls[2].Dock = DockStyle.Fill;tableLayoutPanel2.Hide();
}

}

private void cogRecordDisplay4_DoubleClick(object sender, EventArgs e)
{
Cognex.VisionPro.CogRecordDisplay recordDisplay = sender as Cognex.VisionPro.CogRecordDisplay;
if (bEnlarge)
{
//再次双击鼠标恢复
bEnlarge = false;

    tableLayoutPanel2.Controls.Add(displayControls[3]);displayControls[3].SendToBack();displayControls[3].Parent = tableLayoutPanel2;displayControls[3].Dock = DockStyle.Fill;tableLayoutPanel2.Show();
}
else
{//双击鼠标放大bEnlarge = true;tableLayoutPanel2.Controls.Remove(displayControls[3]);displayControls[3].Parent = this;displayControls[3].BringToFront();displayControls[3].Dock = DockStyle.Fill;tableLayoutPanel2.Hide();
}

}

private void cogRecordDisplay5_DoubleClick(object sender, EventArgs e)
{
Cognex.VisionPro.CogRecordDisplay recordDisplay = sender as Cognex.VisionPro.CogRecordDisplay;
if (bEnlarge)
{
//再次双击鼠标恢复
bEnlarge = false;

    tableLayoutPanel2.Controls.Add(displayControls[4]);displayControls[4].SendToBack();displayControls[4].Parent = tableLayoutPanel2;displayControls[4].Dock = DockStyle.Fill;tableLayoutPanel2.Show();
}
else
{//双击鼠标放大bEnlarge = true;tableLayoutPanel2.Controls.Remove(displayControls[4]);displayControls[4].Parent = this;displayControls[4].BringToFront();displayControls[4].Dock = DockStyle.Fill;tableLayoutPanel2.Hide();
}

}

private void cogRecordDisplay6_DoubleClick(object sender, EventArgs e)
{
Cognex.VisionPro.CogRecordDisplay recordDisplay = sender as Cognex.VisionPro.CogRecordDisplay;
if (bEnlarge)
{
//再次双击鼠标恢复
bEnlarge = false;

    tableLayoutPanel2.Controls.Add(displayControls[5]);displayControls[5].SendToBack();displayControls[5].Parent = tableLayoutPanel2;displayControls[5].Dock = DockStyle.Fill;tableLayoutPanel2.Show();
}
else
{//双击鼠标放大bEnlarge = true;tableLayoutPanel2.Controls.Remove(displayControls[5]);displayControls[5].Parent = this;displayControls[5].BringToFront();displayControls[5].Dock = DockStyle.Fill;tableLayoutPanel2.Hide();
}

}
#endregion


http://www.ppmy.cn/server/151240.html

相关文章

Flink DataStream API 编程指南

(对于Flink的开发,建议使用Java,Scala的支持未来会被移除) DataStream是什么 DataStream API得名于DataStream这个Java类,可以将它们视为可以包含重复项的不可变数据集合。该数据可以是有限的,也可以是无限的,用于处理它们的API是相同的。 DataStream在用法上和普通的…

试题转excel;word转excel;大风车excel

一、问题描述 一名教师朋友&#xff0c;偶尔会需要整理一些高质量的题目到excel中 以往都是手动复制搬运&#xff0c;几百道题几乎需要一个下午的时间 关键这些事&#xff0c;枯燥无聊费眼睛&#xff0c;实在是看起来就很蠢的工作 就想着做一个工具&#xff0c;可以自动处理…

glTF格式:WebGL应用的3D资产优化解决方案

摘要 glTF作为一种高效的3D资产格式&#xff0c;为WebGL、OpenGL ES和OpenGL运行时的应用提供了强有力的支持。它不仅简化了3D模型的传输与加载流程&#xff0c;还通过优化资产大小&#xff0c;使得打包、解包更加便捷。本文将深入探讨glTF格式的优势&#xff0c;并提供实用的代…

Sql注入(靶场)14-20关

第十四关 跟上面一样闭合换成" 第一步查询库名 " and updatexml(1,concat(1,(select database())),1)# 第二步查询表名 " and updatexml(1,concat(1,(select group_concat(table_name) from information_schema.tables where table_schemasecurity)),1)# 第…

开源Java快速自测工具,可以调用系统内任意一个方法

java快速测试框架&#xff0c;可以调到系统内任意一个方法&#xff0c;告别写单测和controller的困扰。 开源地址&#xff1a;https://gitee.com/missyouch/Easy-JTest 我们在开发时很多时候想要测试下自己的代码&#xff0c;特别是service层或者是更底层的代码&#xff0c;就…

【Qt】QWidget中的常见属性及其功能(一)

目录 一、 enabled 例子&#xff1a; 二、geometry 例子&#xff1a; window fram 例子 &#xff1a; 四、windowTiltle 五、windowIcon 例子&#xff1a; qrc机制 创建qrc文件 例子&#xff1a; qt中的很多内置类都是继承自QWidget的&#xff0c;因此熟悉QWidget的…

Python数据分析(OpenCV视频处理)

处理视频我们引入的还是numpy 和 OpenCV 的包 引入方式如下&#xff1a; import numpy as np import cv2 我们使用OpenCV来加载本地视频&#xff0c;参数就是你视频的路径就可以 #加载视频 cap cv2.VideoCapture(./1.mp4) 下面我们进行读取视频 #读取视频 flag,frame cap.re…

第六章:反射+设计模式

一、反射 1. 反射 (Reflection) &#xff1a;允许在程序运行状态中&#xff0c;可以获取任意类中的属性和方法&#xff0c;并且可以操作任意对象内部的属 性和方法&#xff0c;这种动态获取类的信息及动态操作对象的属性和方法对应的机制称为反射机制。 2. 类对象 和 类的…