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

启动窗体自动输入上次内容——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、致命错误、闪退等。

相关文章:

  • 50. Pow(x, n)
  • 『 测试 』软件测试全流程与Bug管理核心要点解析
  • 前端~三维地图(cesium)动态材质扩散圆环
  • 编译openssl源码
  • LLM定制新路径:微调与上下文学习的博弈与融合
  • JS中本地存储(LocalStorage)和会话存储(sessionStorage)的使用和区别
  • python使用matplotlib画图
  • 交易所功能设计的核心架构与创新实践
  • 日语学习-日语知识点小记-构建基础-JLPT-N4阶段(21):复习
  • 一般枚举题目合集
  • 【HALCON】 HALCON 教程:正确使用 `get_dict_tuple` 获取字典内容
  • gd32e230c8t6 keil6工程模板
  • loss = -F.log_softmax(logits[:, -1, :], dim=1)[0, irrational_id]
  • 快消零售AI转型:R²AIN SUITE如何破解效率困局
  • CK-S654-PA60一拖四分体式半导体电子货架专用RFID读写器|读码器接线使用说明
  • java day 11
  • acwing 1488. 最短距离 超级源点 最短路 堆优化Dijkstra
  • 03_朴素贝叶斯分类
  • The 2022 ICPC Asia Xian Regional Contest(E,L)题解
  • 鸿蒙:DevEco Studio配置ohpm时,cmd正常,在终端出现‘ohpm‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
  • 嘉兴服饰网站建设/百度公司招聘官网最新招聘
  • 杭州网站建设设计公司/百度导航和百度地图
  • 网站结构分析怎么写/长沙网站seo分析
  • 广州微网站开发/seo实战教程
  • 网站的流量建设/seo怎么发文章 seo发布工具
  • 大学生兼职网站开发毕设论文/24小时人工在线客服