C#窗口设计|实现两个功能,一个是字母大小写的转换,第二个为数字位置查找

实现两个功能

一个是字母大小写的转换,第二个为数字位置查找

实现窗口设计

本次窗口使用的是五个label,五个textBox和三个button来实现本次窗口的功能,顺序为从左到右。button1实现数字位置的查找,button2实现字母大小写之间的转换,button3实现对所有的输入框进行内容清空。

在这里插入图片描述

实现的窗口如下图所示:

在这里插入图片描述

具体代码如下

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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("输入数组框未输入");
            }
            if (textBox3.Text == "")
            {
                MessageBox.Show("输入查找数字框未输入");
            }
            string a = textBox1.Text;
            string[] b = a.Split('/');
            int[] c = new int[b.Length];
            for (int i = 0; i < b.Length; i++)
            {
                int temp = Convert.ToInt32(b[i]);
                c[i] = temp;
            }
            int g = Convert.ToInt32(textBox3.Text);
            int f =-1;
            for (int i = 0; i < c.Length; i++)
            {
                if (g == c[i])
                {
                    f = i + 1;
                    break;
                }
            }
            textBox5.Text += f;

        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                MessageBox.Show("输入字母框未输入");
            }
          
            string a = textBox2.Text;
            int b = 'A' - 'a';
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] >= 'a' && a[i] <= 'z')
                {
                    Char c = (Char)(a[i] + b);
                    textBox4.Text += c;
                }
                else if (a[i] >= 'A' && a[i] <= 'z')
                {
                    Char c = (Char)(a[i] - b);
                    textBox4.Text += c;
                }
                else
                {
                    textBox4.Text += a[i];
                }
            }
            textBox4.Text += "\n";

        }
    }
    }


本文总结

文章若出现缺少和错误之处,欢迎大家在评论区留言,纠正错误,补充本文不足之处,互相学习交流,在此共勉。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值