C#实现关闭子窗口而不释放子窗口对象的方法
作者:jingxian 时间:2022-09-11 12:41:02
在线扫描相机的调试过程中,需要开辟调试界面来进行位置的配置。调试结束后,一种常用的方式是将调试参数保存并在下次启动时加载。另一种简单方式是直接使用该参数运行程序。因此,在后一种情况下,需要实现的功能是:即使关闭调试窗口,其窗口对象也不释放。除非其主窗口关闭,才销毁其调试窗口的对象。
1 在主窗口中实例化子窗口
在主窗口中实例化子窗口,而不是在按钮中实例化子窗口对象。
Form2 f2 = new Form2();
2 通过按钮来显示主窗口
在按钮中需要实现的是窗口的显示
private void Config_Click(object sender, EventArgs e)
{
f2.Show();
}
3 关闭子窗口而不释放子窗口对象的方法
经查询和实证,修改子窗口中Dispose的方法是可行的。更改如下:
protected override void Dispose(bool disposing)
{
Hide();
//if (disposing && (components != null))
//{
// components.Dispose();
//}
//base.Dispose(disposing);
}
4 在父窗口关闭时销毁子窗口对象
由于需要在父窗口关闭是销毁子窗口对象,因此,在父窗口的关闭动作FormClosed中添加调用子窗口f2的销毁函数。
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
f2.Close();
}
子窗口类中添加的关闭函数如下:
public void Close()
{
this.Dispose();
}
标签:c#,子窗口,对象
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java BufferedImage转换为MultipartFile方式
2022-07-13 10:02:46
C#多线程基础知识汇总
2023-03-06 08:35:47
![](https://img.aspxhome.com/file/2023/3/86963_0s.png)
详解用Spring Boot Admin来监控我们的微服务
2022-02-12 15:18:03
OpenCV实现简单摄像头视频监控程序
2021-12-10 01:23:07
Druid(新版starter)在SpringBoot下的使用教程
2021-07-03 20:25:18
![](https://img.aspxhome.com/file/2023/1/103841_0s.png)
C# 如何设置label(标签)控件的背景颜色为透明
2023-05-27 11:03:00
![](https://img.aspxhome.com/file/2023/2/79042_0s.jpg)
Java创建子线程的两种方法
2023-11-24 07:00:05
Android Studio一直处于Building的两种解决方法
2022-06-13 23:05:22
![](https://img.aspxhome.com/file/2023/4/96024_0s.png)
Android实现Banner界面广告图片循环轮播(包括实现手动滑动循环)
2022-02-06 17:05:35
![](https://img.aspxhome.com/file/2023/1/93261_0s.gif)
Java深入讲解instanceof关键字的使用
2023-02-27 13:05:05
![](https://img.aspxhome.com/file/2023/8/60998_0s.png)
ibatis学习之搭建Java项目
2021-11-02 00:35:29
一文带你搞懂Java中方法重写与方法重载的区别
2022-05-14 03:19:13
![](https://img.aspxhome.com/file/2023/5/101805_0s.webp)
IDEA 2020 本土化,真的是全中文了(真香)
2023-11-25 08:02:58
![](https://img.aspxhome.com/file/2023/6/60196_0s.png)
Hibernate批量处理海量数据的方法
2023-07-30 08:12:04
Java 接口和抽象类的区别详解
2021-07-26 13:30:21
详解JDK中ExecutorService与Callable和Future对线程的支持
2023-11-25 07:39:07
C# 超高面试题收集整理
2022-01-20 17:28:59
SpringMVC后端返回数据到前端代码示例
2023-06-20 13:12:47
SpringBoot3.0整合chatGPT的完整步骤
2023-01-29 01:34:36
![](https://img.aspxhome.com/file/2023/2/104962_0s.png)
java泛型基本知识和通用方法
2023-09-19 12:59:12