zoukankan      html  css  js  c++  java
  • C#实现矩阵转换功能

        实现下图矩阵转换功能。

        矩阵由一个4*4的文本框数据表示,在相应文本框中输入矩阵元的值,单击“转换”按钮,完成矩阵的转换。

     代码如下:

    public partial class Form1 : Form
        {
            TextBox[,] tbList 
    = null;
            
    public Form1()
            {
                InitializeComponent();
                
    //得到界面的矩型TexbBox控件
                tbList = new TextBox[44] {
                    {txb11,txb12,txb13,txb14},
                    {txb21,txb22,txb23,txb24},
                    {txb31,txb32,txb33,txb34},
                    {txb41,txb42,txb43,txb44},
                };
            }
            
    /// <summary>
            
    /// 转换开关
            
    /// </summary>
            string sSwitch = "0";

            
    private void Convert()
            {   
                
    if (sSwitch=="0")
                {
                    sSwitch 
    = "1";
                    btnConvert.Text 
    = "返原";
                }
                
    else
                {
                    sSwitch 
    = "0";
                    btnConvert.Text 
    = "转换";
                }

                
    string[,] sList = new string[44];
                
    //得到界面所有值
                for (int iRow = 0; iRow < 4; iRow++)
                {
                    
    for (int iCol = 0; iCol < 4; iCol++)
                    {
                        sList[iRow, iCol] 
    = tbList[iRow, iCol].Text;
                    }
                }

                
    string sTemp = "";
                
    //得到倒置结果
                for (int iRow = 0; iRow < 4; iRow++)
                {
                    
    for (int iCol = iRow; iCol < 4; iCol++)
                    {
                        sTemp 
    = sList[iRow, iCol];
                        sList[iRow, iCol] 
    = sList[iCol, iRow];
                        sList[iCol, iRow] 
    = sTemp;
                    }
                }
                
    //界面显示
                for (int iRow = 0; iRow < 4; iRow++)
                {
                    
    for (int iCol = 0; iCol < 4; iCol++)
                    {
                        tbList[iRow, iCol].Text 
    = sList[iRow, iCol];
                    }
                }
            }

            
    private void btnConvert_Click(object sender, EventArgs e)
            {
                Convert();
            }

            
    private void btnCancel_Click(object sender, EventArgs e)
            {
                
    //清除所有值
                for (int iRow = 0; iRow < 4; iRow++)
                {
                    
    for (int iCol = 0; iCol < 4; iCol++)
                    {
                        tbList[iRow, iCol].Text 
    = "";
                    }
                }
            }
        }

  • 相关阅读:
    佛教:禅宗和净土--佛教的归途
    佛教:从精英到世俗
    佛教:神迹的演变。
    收藏品:MP3播放器
    淘书百胜楼
    Spring注解是如何生效的?
    logstash6.8.3 导入 CSV 文件到 ElasticSearch
    三个线程交替按顺序打印ABC之条件队列的理解
    谈谈多线程
    ElasticSearch如何更新集群的状态
  • 原文地址:https://www.cnblogs.com/scottckt/p/1328512.html
Copyright © 2011-2022 走看看