在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
实现下图矩阵转换功能。 矩阵由一个4*4的文本框数据表示,在相应文本框中输入矩阵元的值,单击“转换”按钮,完成矩阵的转换。
代码如下:
public partial class Form1 : Form
{ TextBox[,] tbList = null; public Form1() { InitializeComponent(); //得到界面的矩型TexbBox控件 tbList = new TextBox[4, 4] { {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[4, 4]; //得到界面所有值 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 = ""; } } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论