コード例 #1
0
        private void btnLerArquivo_Click(object sender, EventArgs e) //Gera a Matriz 1 por meio da leitura de um arquivo
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var arquivo = new StreamReader(openFileDialog1.FileName);

                //Lê as linhas e colunas do arquivo
                int linhasArq  = int.Parse(arquivo.ReadLine());
                int colunasArq = int.Parse(arquivo.ReadLine());

                //Cria a matriz com as linhas e colunas desejadas
                matriz1 = new ListaCruzada(linhasArq, colunasArq);

                //Trata o arquivo lido e insere os valores na matriz em suas respectivas linhas e colunas
                string linha = arquivo.ReadLine();
                linha = linha.Replace('(', ' ');
                linha = linha.Replace(')', ' ');
                linha = linha.Replace('{', ' ');
                linha = linha.Replace('}', ' ');
                linha.Trim();
                string[] matrizString = linha.Split(',');
                for (int i = 0; i < matrizString.Length;)
                {
                    int linhaCelula = int.Parse(matrizString[i]);
                    i++;
                    int colunaCelula = int.Parse(matrizString[i]);
                    i++;
                    double valor = double.Parse(matrizString[i]);
                    i++;

                    matriz1.InserirCelula(linhaCelula, colunaCelula, valor);
                }
                arquivo.Close();
                matriz1.Exibir(ref dgvMatriz1);

                //Altera a visibilidade de outros elementos
                btnLerArquivoMatriz1.Enabled = false;
                btnGerarMatriz1.Enabled      = false;
                lMatriz1.Enabled             = true;
                gbOperacoes1.Visible         = true;
            }
        }
コード例 #2
0
 private void btnInserirValorMatriz2_Click(object sender, EventArgs e)
 {
     //Insere o valor na matriz
     matriz2.InserirCelula(Convert.ToInt32(Math.Round(nLinhaMatriz2.Value, 0)), Convert.ToInt32(Math.Round(nColunaMatriz2.Value, 0)), Convert.ToDouble(txtValorMatriz2.Text));
     matriz2.Exibir(ref dgvMatriz2);
 }
コード例 #3
0
 private void btnInserirValorMatriz1_Click(object sender, EventArgs e)
 {
     //Insere o valor na linha e coluna desejada e re-exibe a matriz no DataGridView
     matriz1.InserirCelula(Convert.ToInt32(Math.Round(nLinha.Value, 0)), Convert.ToInt32(Math.Round(nColuna.Value, 0)), Convert.ToDouble(txtValorMatriz1.Text));
     matriz1.Exibir(ref dgvMatriz1);
 }