当前位置: 首页 > ai >正文

启动窗体自动输入上次内容——CAD c#二次开发

 

 上面红色框中两个文件,若不存在或内容不规范,需要修改如下:

Settings.cs:

namespace IfoxDemo.Properties
{[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()][global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")]internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase{private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));public static Settings Default => defaultInstance;[global::System.Configuration.UserScopedSettingAttribute()][global::System.Diagnostics.DebuggerNonUserCodeAttribute()]public string TB1 {get => ((string)(this["TB1"]));set => this["TB1"] = value;}[global::System.Configuration.UserScopedSettingAttribute()][global::System.Diagnostics.DebuggerNonUserCodeAttribute()]public string TB2 {get => ((string)(this["TB2"]));set => this["TB2"] = value;}[global::System.Configuration.UserScopedSettingAttribute()][global::System.Diagnostics.DebuggerNonUserCodeAttribute()]public string TB3 {get => ((string)(this["TB3"]));set => this["TB3"] = value;}}
}

 Settings.settings:

<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="IfoxDemo.Properties" GeneratedClassName="Settings"><Profiles><Profile Name="(Default)" /></Profiles><Settings><Setting Name="TB1" Type="System.String" Scope="User"><Value Profile="(Default)" /></Setting><Setting Name="TB2" Type="System.String" Scope="User"><Value Profile="(Default)" /></Setting><Setting Name="TB3" Type="System.String" Scope="User"><Value Profile="(Default)" /></Setting></Settings>
</SettingsFile>

 在窗体文件中加入以下代码:

  public Form1(){InitializeComponent();// 窗体加载时触发(也可以写在 Form1_Load 事件中)this.Load += (sender, e) =>{// 从用户设置中读取上次保存的值(如果没有则为空)textBox1.Text = Properties.Settings.Default.TB1; // 对应 TB1textBox2.Text = Properties.Settings.Default.TB2; // 对应 TB2textBox3.Text = Properties.Settings.Default.TB3; // 对应 TB3// 窗体关闭时保存当前值this.FormClosing += (sender, e) =>{Properties.Settings.Default.TB1 = textBox1.Text;Properties.Settings.Default.TB2 = textBox2.Text;Properties.Settings.Default.TB3 = textBox3.Text;Properties.Settings.Default.Save(); // 必须调用 Save()};};}

窗体项目最好不要把doc ed db等做成静态函数,因为用户可能换个dwg文件继续执行窗体,这时候代码中的doc还是老dwg,容易造成bug、致命错误、闪退等。

http://www.xdnf.cn/news/6150.html

相关文章:

  • MySQL--day1--数据库概述
  • [20250514] 脑机接口行业调研报告(2024年最新版)
  • Sunsetting 创建 React App
  • 斜率变化策略
  • 手写CString类
  • UniApp Vue3事件适配与兼容方案
  • python 练习 五
  • IIS服务器URL重写配置完整教程
  • MySQL视图:虚拟表的强大功能与应用实践
  • 国产化环境下的 DICOM 网络服务与影像处理适配
  • Yolov8的详解与实战-深度学习目标检测
  • 关于vue学习的经常性错误
  • KUKA库卡焊接机器人智能气阀
  • 亚远景-对ASPICE评估体系的深入研究与分析
  • ConfigMap 和 Secret 是否支持热更新
  • 系统单元测试和项目打包
  • Jmeter -- JDBC驱动连接数据库超详细指南
  • 东莞文件服务器存储维修-DELL MD3400电池故障
  • C++学习细节回顾(汇总二)
  • 基于Spring AI与Hugging Face TGI构建高效聊天应用:从配置到实践全解析
  • centos中postfix的作用
  • 用git下载vcpkg时出现Connection was reset时的处理
  • SpringBoot集成Kafka
  • Python × CARLA:如何在自动驾驶仿真世界里打造智能驾驶系统?
  • ansible进阶02
  • vivado原语
  • AI编程:使用Trae + Claude生成原型图,提示词分享
  • 一次因校时服务器异常引起的性能差异分析
  • 浏览器相关
  • React Native矢量图标全攻略:从入门到自定义iconfont的高级玩法