电阻色环查询器[原创]

   本人有一个朋友是学电路的。这几天,找到了我 想让我给写一个电阻色环查询器(根据电阻上面表明的色环颜色,判断电阻的大小)。由于,不是电路的翻阅的许多资料,才知道怎么根据色环查阻值。今天,把源码发上来与大家学习一下。注:由于时间仓促只完成的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;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值