实验6-C#多项目开发

1、使用三个窗体模块文件及一个标准模块文件,使输入字符串以不同形式显示。

程序设计:


程序代码:

//定义公共类
namespace WindowsFormsApplication1
{
    class PublicClass
    {
        public string fnClsSpace(string s)//去除字符串空格
        {
            string strReturn = s.Replace(" ", "");
            return strReturn; 
        }

        public string fnInverSt(string s)//字符串反向输出
        {
            char[] w=s.ToCharArray();
            Array.Reverse(w);
            return new string(w);
        }
    }
}

namespace WindowsFormsApplication1
{
    //清除空格窗体
    public partial class frmCls : Form
    {
        public frmCls()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PublicClass puC=new PublicClass();
           textBox2.Text = puC.fnClsSpace(textBox1.Text);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            frmSel frmSel = new frmSel();
            frmSel.Show();
        }
    }
}


namespace WindowsFormsApplication1
{
    //反向排列窗体
    public partial class frmInver : Form
    {
        public frmInver()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PublicClass puC=new PublicClass();
            textBox2.Text = puC.fnInverSt(textBox1.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            frmSel f = new frmSel();
            f.Show();
        }
    }
}


namespace WindowsFormsApplication1
{
    //选择窗体
    public partial class frmSel : Form
    {
        public frmSel()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                this.Hide();
                frmInver f1 = new frmInver();
                f1.Show();
            }
            if (radioButton2.Checked == true)
            {
                this.Hide();
                frmCls f2 = new frmCls();
                f2 = new frmCls();
                f2.Show();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

程序运行:


©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页