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 
    = "";
                    }
                }
            }
        }

  • 相关阅读:
    对于线程同步的浅薄理解
    线程安全之ConcurrentQueue<T>队列
    关于mybatis拦截器,对结果集进行拦截
    oracle 分析函数
    C# ikvm 运行htmlunit Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found
    IronJs 无相关源?
    js div 内容显示分页
    JavascriptTAB切换 AND JqueryTAB切换
    php中mysql数据库操作类 -李盛鹏 -博客园
    sublime text 之snippet功能的使用 -李盛鹏 -博客园
  • 原文地址:https://www.cnblogs.com/scottckt/p/1328512.html
Copyright © 2011-2022 走看看