实现两个功能
一个是字母大小写的转换,第二个为数字位置查找
实现窗口设计
本次窗口使用的是五个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";
}
}
}
本文总结
文章若出现缺少和错误之处,欢迎大家在评论区留言,纠正错误,补充本文不足之处,互相学习交流,在此共勉。