项目需要写个配置的桌面程序,作为一名前端工程师,接到这活我是懵逼的,然而boss说了,公司人人都是全栈工程师。额,好吧,我信了你的鬼,开干开干!

【百度百科】WinForms 脚本都是基于c#,winforms是做客户端软件,WinForm是.Net开发平台中对Windows Form的一种称谓。

对WinForms的第一印象是类似于dreamweaver,可以用视图做些简单的功能。先做个简单外壳,设置页面需要用到label、textBox、checkBox以及Button,如下图所示

外壳做好了,接下来实现业务逻辑,逻辑并不难,主要是对xml格式的文件进行读取、修改、保存等操作,以及桌面程序confirm弹框等基本功能的实现。

xml文件内容:

<?xml version="1.0" encoding="utf-8"?>
<config><UserName>root</UserName><Password>111111</Password><DatabaseName>test</<DatabaseName><ServerIP>localhost</ServerIP><CT_LUNG>1</CT_LUNG><CT_RIB>1</CT_RIB><DR_CHEST>1</DR_CHEST>
</config>

Form1.cs中添加程序的一些功能:

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 System.Xml;
using System.Xml.Linq;namespace WindowsFormsApp1
{public partial class MNConfig : Form{public MNConfig(){InitializeComponent();}static void read(string[] args){}private void MNConfig_Load(object sender, EventArgs e){getXml();}private void save_btn_Click(object sender, EventArgs e){updatexml();}private void exit_btn_Click(object sender, EventArgs e){var a = MessageBox.Show("确认不保存退出吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);if (Convert.ToString(a) == "OK"){this.Close();}}private void getXml(){var responseData = new List<object>();var data = new Dictionary<string, string>();XDocument document = XDocument.Load(@"D:\feb\test.xml");XElement root = document.Root;XElement UserName = root.Element("UserName");XElement Password = root.Element("Password");XElement DatabaseName = root.Element("DatabaseName");XElement ServerIP = root.Element("ServerIP");XElement CT_LUNG = root.Element("CT_LUNG");XElement CT_RIB = root.Element("CT_RIB");XElement DR_CHEST = root.Element("DR_CHEST");this.tbUserName.Text = UserName.Value;this.tbPassword.Text = Password.Value;this.tbDatabaseName.Text = DatabaseName.Value;this.tbServerIP.Text = ServerIP.Value;this.CT_LUNG.Checked = Convert.ToBoolean(Convert.ToInt16(CT_LUNG.Value));this.CT_RIB.Checked = Convert.ToBoolean(Convert.ToInt16(CT_RIB.Value));this.DR_CHEST.Checked = Convert.ToBoolean(Convert.ToInt16(DR_CHEST.Value));}private void updatexml(){XmlDocument xmlDoc = new XmlDocument();xmlDoc.Load(@"D:\feb\test.xml");XmlNode xns = xmlDoc.SelectSingleNode("config");XmlNodeList xnl = xns.ChildNodes;foreach(XmlNode xn in xnl){switch (xn.Name){case "UserName":xn.InnerText = this.tbUserName.Text;break;case "Password":xn.InnerText = this.tbPassword.Text;break;case "DatabaseName":xn.InnerText = this.tbDatabaseName.Text;break;case "ServerIP":xn.InnerText = this.tbServerIP.Text;break;//checkboxcase "CT_LUNG":xn.InnerText = Convert.ToString(Convert.ToInt32(this.CT_LUNG.Checked));break;case "CT_RIB":xn.InnerText = Convert.ToString(Convert.ToInt32(this.CT_RIB.Checked));break;case "DR_CHEST":xn.InnerText = Convert.ToString(Convert.ToInt32(this.DR_CHEST.Checked));break;default:break;}}xmlDoc.Save(@"D:\feb\test.xml");MessageBox.Show("保存成功!");this.Close();}}}

WinForms开发桌面应用程序相关推荐

  1. 为什么用Python开发桌面应用程序

    为什么用Python开发桌面应用程序 为什么用Python开发桌面应用程序 1)wxWidgets是一个比MFC优雅的库,TortoiseCVS用wxWidges而不用MFC,就是因为wxWidget ...

  2. 教你一键开发桌面应用程序

    前言 因为公司项目关系,要开发一款桌面应用程序.说到桌面应用程序,有很多种解决方案,最终我们选了Electron,备受前端开发喜爱的VS Code正是Electron开发的,今天我们就来聊聊这个Ele ...

  3. php开发桌面应用程序_使用PHP开发跨平台桌面应用程序的3种方法

    php开发桌面应用程序 PHP as a cross-platform desktop app development language? Blasphemy! Nonetheless, it's p ...

  4. flask开发桌面应用程序_使用Microsoft Authenticatio将多个破折号应用程序嵌入Flask中...

    flask开发桌面应用程序 Full disclosure: I am not an expert in developing web applications. I don't even consi ...

  5. Python+WebKit+HTML开发桌面应用程序

    Python+WebKit+HTML开发桌面应用程序 前言 几天前写了一个备份的小工具,用Python写个脚本,也就花个一天的时间搞定,给客户用了一下,对功能很满意,但对界面不满足,想要一个图形界面来 ...

  6. window下使用nw.js开发桌面应用程序环境的搭建

    安装node window下去node官网下载长期支持版本或者最新稳定版都可以. 按装nw用来管理和按装nw.js npm install -g nrm # 用来设置npm镜像地址 npm insta ...

  7. linux 桌面程序 一般用什么语言写,什么编程语言比较适合开发桌面应用程序?...

    这个要看具体平台了,如果是Windows系统,那么C#无疑是首选,如果考虑到跨平台,那么C++可能更合适,下面我分别简单介绍一下,感兴趣的朋友可以尝试一下: C# 这是微软自主设计研发的一款编程语言, ...

  8. 用html5,nodeJs开发桌面应用程序

    原文摘自: http://www.webhek.com/html5-native-desktop-app/ HTML5让Web开发人员用纯HTML技术开发富客户端互联网应用或者甚至本地桌面应用成为了可 ...

  9. Python+wxWidgets快速开发桌面小程序

    转载:http://www.blogjava.net/calvin/archive/2005/11/18/20403.html 充分体验到知识循环再用的好处,原本对Python.wxWidgets没有 ...

最新文章

  1. 华为公有云架构解决方案
  2. 如何使用 Arthas 定位 Spring Boot 接口超时
  3. java web方面杂志_环境方面比较好发的期刊_全球环境类最好的期刊_环境领域top期刊...
  4. Android实现连续并排的若干个TextView单击改变背景颜色达到选项卡Tab栏切换效果...
  5. python网页填表教程_PythonSpot 中文系列教程 · 翻译完成
  6. php 动态多维数组长度,php – 动态创建多维数组
  7. 二进制安装mysql集群_实战mysql集群搭建(一)--centos7下二进制安装mysql-5.6
  8. Echo团队Alpha冲刺随笔 - 第八天
  9. 光滑噪声数据常用的方法_数据挖掘部分课后习题
  10. 严数据结构c语言及答案,严蔚敏《数据结构(c语言版)习题集》全答案
  11. markdown emoji表情代码
  12. 【WSL2教程】WSL迁移到非系统盘
  13. CentOS配置yum源-本地和在线
  14. 设计模式 - 创建型模式_工厂方法模式
  15. 写论文第一步——查文献的方法
  16. 用友安装时显示加密服务器,用友云主机指向加密服务器
  17. Python-flask 使用Markdown和Flask-PageDown支持富文本文章
  18. NBS云硬盘无法挂载
  19. 华为云正式推出区块链服务!区块链技术将在数字经济时代大放异彩
  20. json能传数字,不能传字符串

热门文章

  1. STM32之ADM706驱动
  2. 华为OD机试 - 二进制差异数(Java JS Python)
  3. 监控摄像头故障检测修复过程
  4. 主题 06:如何高效地排查 Java 系统异常
  5. 骨传导耳机原理,骨传导耳机优缺点
  6. 1+X”中级Web前端证书对应课程分析
  7. MapReduce实现寻找共同好友
  8. Excel | 基因名都被Excel篡改了怎么办呢!?~(附3种解决方案)
  9. ca证书 csr_ca证书csr crt cer
  10. JavaScript的输入输出语句