本人有一个朋友是学电路的。这几天,找到了我 想让我给写一个电阻色环查询器(根据电阻上面表明的色环颜色,判断电阻的大小)。由于,不是电路的翻阅的许多资料,才知道怎么根据色环查阻值。今天,把源码发上来与大家学习一下。注:由于时间仓促只完成的4环型的,且代码不太规范 【高手无喷】

namespace DianZuChaXunQi
{
    public partial class Form1 : Form
    {

public Form1()
        {
            InitializeComponent();

}
        List<string> l;
        List<Color> fontColor;
        List<int> lis;
        List<string> historyList = new List<string>();
        int f = 0;
        int s = 0;
        int t = 0;
        int f4 = 0;
        string history = null;
        private void Form1_Load(object sender, EventArgs e)
        {

fontColor = new List<Color>();
            fontColor.AddRange(new Color[] {Color.Black,Color .Brown ,Color .Red ,Color .Orange ,Color .Yellow ,Color .Green
                 ,Color .Blue ,Color.Purple ,Color.Gray ,Color .White ,Color .Gold ,Color .Silver });
            ComboBoxItemAdd(1);
            int[] num = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 10 };
            lis = new List<int>();
            lis.AddRange(num);
        }
        private void ComboBoxItemAdd(int style)
        {
            string str_Color = "黑.棕.红.橙.黄.绿.蓝.紫.灰.白.金.银";
            string[] colorList = str_Color.Split(new char[] { '.' });
            l = new List<string>();
            l.AddRange(colorList);
            switch (style)
            {
                case 1:
                    l.RemoveAt(10);
                    l.RemoveAt(l.Count - 1);
                    break;
                case 2:
                    l.RemoveAt(0);
                    l.RemoveAt(2);
                    l.RemoveAt(2);
                    l.RemoveAt(5);
                    l.RemoveAt(5);
                    fontColor.RemoveAt(0);
                    fontColor.RemoveAt(2);
                    fontColor.RemoveAt(2);
                    fontColor.RemoveAt(5);
                    fontColor.RemoveAt(5);
                    break;
                default:
                    break;
            }
            yi.Items.Clear();
            foreach (string cs in l)
            {
                this.yi.Items.Add(cs);
            }
        }

private void yi_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        private bool FeiFaXuanZe(int a, int b)
        {
            bool bb = true;
            if (yi.SelectedIndex == a || yi.SelectedIndex == b)
            {
                MessageBox.Show("选择非法请重选!");
                bb = false;
            }
            else
            {
                bb = true;
            }
            return bb;
        }
        private void yi_SelectedValueChanged(object sender, EventArgs e)
        {
            if (this.l1.Text == "无")
            {
                l1.Text = yi.SelectedItem.ToString();
                f = lis[yi.SelectedIndex];
                l1.ForeColor = fontColor[yi.SelectedIndex];
                history += l1.Text;
            }
            else
            {
                if (l2.Text == "无")
                {
                    l2.Text = yi.SelectedItem.ToString();
                    s = lis[yi.SelectedIndex];
                    l2.ForeColor = fontColor[yi.SelectedIndex];
                    history += l2.Text;
                }
                else
                {
                    if (l3.Text == "无")
                    {
                        l3.Text = yi.SelectedItem.ToString();
                        t = lis[yi.SelectedIndex];
                        l3.ForeColor = fontColor[yi.SelectedIndex];
                        ComboBoxItemAdd(2);
                        history += l3.Text;
                    }
                    else
                    {
                        if (l4.Text == "无")
                        {
                            l4.Text = yi.SelectedItem.ToString();
                            history += l4.Text;
                            lis.Remove(0);
                            lis.Remove(3);
                            lis.Remove(4);
                            lis.Remove(8);
                            lis.Remove(9);
                            f4 = lis[yi.SelectedIndex];
                            l4.ForeColor = fontColor[yi.SelectedIndex];
                        }
                        else
                        { return; }
                    }

}
            }
        }

private void button1_Click(object sender, EventArgs e)
        {

string word = "无";
            if (l1.Text == word || l2.Text == word || l3.Text == word || l4.Text == word)
            {
                MessageBox.Show("你还有没有选择的色环!请继续选择!!");
            }
            else
            {
                this.label5.Text = Fun(f, s, t, f4);
                if (history != null)
                {

if (historyList.Contains(history) == false )
                    {
                        historyList.Add(history);
                        ListViewItem lst = new ListViewItem(history);
                        lst.SubItems.Add(label5.Text);
                        this.listView1.Items.Add(lst);
                    }
                }
                fun1(sender, e);
            }
           
        }
        private string Fun(int a, int b, int c, int d)
        {
            Dictionary<int, float> WuCha = new Dictionary<int, float>();
            WuCha.Add(1, 1);
            WuCha.Add(2, 2);
            WuCha.Add(5, 0.5f);
            WuCha.Add(6, 5);
            WuCha.Add(7, 5);
            WuCha.Add(10, 5);
            WuCha.Add(11, 10);
            string request = (a * 10 + b).ToString() + "e" + c.ToString() + "±" + WuCha[d] + "%";
            return request;
           
        }

private void button2_Click(object sender, EventArgs e)
        {
            fun1(sender ,e);
        }
        private void fun1(object sender, EventArgs e)
        {
            Form1_Load(sender, e);
            Label[] lab = { l1, l2, l3, l4 };
            foreach (Label tt in lab)
            {
                tt.Text = "无";
                tt.ForeColor = System.Drawing.SystemColors.GradientActiveCaption;
            }

this.history = null;
        }

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (MessageBox.Show("是否确认删除!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                this.listView1.Items.Clear();
                historyList.Clear();
            }
            else
                return;
        }

电阻色环查询器[原创]相关推荐

  1. 建筑幕墙单元体.组装件.零部件计算.查询器(Excel VBA版)

    ​前言: 本篇是建筑幕墙零部件计算器(Excel版)的使用说明书. 零部件计算与查询器为建筑幕墙设计专用程序,适用于有查询及算料需求的幕墙设计或工厂算料人员使用.(程序亦适用于迭代递归的材料计算) 程 ...

  2. 游戏热血江湖 满线自动查询器制作游戏分析脱壳与查询器源码分享

    热血江湖满线自动查询器制作 N久没玩网游,某天心血来潮想去了热血江湖,如是用以前的账号,尝试着无聊一下,结果发现热血江湖现在竟然异常火爆,服务器满线,尝试着登录的几个大号都满线,不只知道啥时候能登录, ...

  3. DIY一个DNS查询器:了解DNS协议

    每当我们在浏览器上敲入任何一个域名访问某个网站的时候,我们都要使用Dns协议进行一次"域名:IP"的查询;作为命令行使用者,与dns有关用的最多的就是Nslookup 命令吧:作为 ...

  4. Android Gradle查询器

    Android Gradle查询器 Gradle please 官网:http://gradleplease.appspot.com/ Gradle please是一个在线工具,它能帮助你找到Grad ...

  5. mysql 连接查询_Swoole 实战:MySQL 查询器的实现(协程连接池)

    Swoole 实战:MySQL 查询器的实现(协程连接池) 需求分析 本篇我们将通过 Swoole 实现一个自带连接池的 MySQL 查询器: 1. 支持通过链式调用构造并执行 SQL 语句: 2. ...

  6. python实现火车票查询_python实现12306火车票查询器

    12306火车票购票软件大家都用过,怎么用Python写一个命令行的火车票查看器,要求在命令行敲一行命令来获得你想要的火车票信息,下面通过本文学习吧. Python火车票查询器 接口设置 先给这个小应 ...

  7. css3 media媒体查询器用法总结

    原文地址:http://www.cnblogs.com/zhaodifont/p/3858657.html 随着响应式设计模型的诞生,Web网站又要发生翻天腹地的改革浪潮,可能有些人会觉得在国内IE6 ...

  8. 【JEECG技术博文】Jeecg高级查询器

    一.背景       对于用户来讲查询功能按易用性分三个层次: 1. 最简单查询操作是一个输入框,全文检索,如百度,后台实现技术使用搜索引擎,需要设计和建立索引,技术较为复杂,适用于文档和信息数据库检 ...

  9. elasticsearch的查询器query与过滤器filter的区别

    很多刚学elasticsearch的人对于查询方面很是苦恼,说实话es的查询语法真心不简单-  当然你如果入门之后,会发现elasticsearch的rest api设计是多么有意思. 说正题,ela ...

最新文章

  1. .net连接mysql数据_.net连接MYSQL数据库的方法及示例!
  2. Android -- 使用inBitmap要注意的地方
  3. 分享Kali Linux 2016.2第48周镜像文件
  4. Oracle增加修改删除字段/主键
  5. 一些常见的Find 命令
  6. 冷链食品竟然也有 “身份证”?
  7. SasSHRM中基于shiro的认证授权:系统微服务配置shiro
  8. python画平面直角坐标系_Python之OpenGL笔记(20):画平面直角坐标系
  9. 使用IntelliJ IDEA的原因
  10. lucene3.0中使用MultiFieldQueryParser多字段查找
  11. avs3 ts格式封装 标准_第480期【软件】吊打格式工厂—高清视频转换器WonderFox HD Video便携版...
  12. 如何系统地自学前端(女生),女生发展前端是否是青春饭?
  13. 小米要用 AI + IoT 做年轻人的第一套智能家居
  14. iosxib 设置图片_iOS framework制作及使用(包含xib和图片)
  15. 64 位SQL Server 2005通过DB link链接32位SQL Server 2000 的bug解决
  16. 智能时尚:人工智能在时尚服装行业的应用综述 | 580+参考文献
  17. 计算机科学与技术军训,计算机科学与技术学院召开2018级新生军训动员大会
  18. AVD安卓模拟器黑屏
  19. 什么是SystemUI
  20. What comes after microservice?

热门文章

  1. 百田游戏2014笔试题——找到有序序列中某个值第一次出现的位置,并打印
  2. C语言程序设计第五章循环结构程序设计总结
  3. 如何解决win11“无法枚举容器中的对象,访问被拒绝”、“右键新建只有文件夹,没有其他选项”的问题。
  4. ICMP----ping报文格式
  5. 教育邮箱申请jetbrains产品,免费获得AppCode、DataSpell、dotMemory、GoLand、IntelliJ IDEA、PhpStorm、PyCharm专业版
  6. windows已经阻止此软件因为无法验证发行者,然后就是IE的控件iNetOffice5.CAB不能安装?
  7. java中string类型的哈希值是怎么计算的
  8. border-radius 圆角 ios 失效
  9. 矩阵论 - 9 - 线性无关、基、维数
  10. Nginx 代理配置