private void btnLerArquivo_Click(object sender, EventArgs e) // permite que o usuário exiba a matriz após a leitura { if (dlgArquivo.ShowDialog() == DialogResult.OK) { arquivo = dlgArquivo.FileName; if (File.Exists(arquivo)) { matriz = new ListaCruzada(new StreamReader(arquivo)); } else { File.Create(arquivo); } alterandoTextDimensao = true; txtLargura.Text = matriz.Colunas.ToString(); txtAltura.Text = matriz.Linhas.ToString(); alterandoTextDimensao = false; dgv.RowCount = matriz.Linhas; dgv.ColumnCount = matriz.Colunas; exibindoMatriz = true; matriz.Exibir(ref dgv); exibindoMatriz = false; btnExcluirMatriz.Enabled = true; btnExcluirCelula.Enabled = true; btnExibirCelula.Enabled = true; label1.Enabled = true; label2.Enabled = true; nUDColuna.Enabled = true; nUDLinha.Enabled = true; btnAdicionarK.Enabled = true; } }
private void btnSomar_Click(object sender, EventArgs e) { //Pega a coluna em que a constante de ser somada int colunas = Convert.ToInt32(Math.Round(nColunaMatriz2.Value, 0)); //Soma o valor e re-exibe a matriz no DataGridView matriz2.SomarK(colunas, Convert.ToDouble(txtValorkMatriz2.Text)); matriz2.Exibir(ref dgvMatriz2); }
private void btnRemoverValorMatriz1_Click(object sender, EventArgs e) { //Pega a linhas e coluna a ser removida int linhas = Convert.ToInt32(Math.Round(nColunaMatriz2.Value, 0)); int colunas = Convert.ToInt32(Math.Round(nLinhaMatriz2.Value, 0)); //Remove o valor e re-exibe a matriz no DataGridView lblValorMatriz2.Text = "0"; matriz1.ExcluirCelula(linhas, colunas); matriz1.Exibir(ref dgvMatriz1); }
private void btnCriar_Click(object sender, EventArgs e) { if (txtAltura.Text != "" && txtLargura.Text != "" && !alterandoTextDimensao) { int l = int.Parse(txtAltura.Text); int c = int.Parse(txtLargura.Text); nUDColuna.Maximum = c; nUDLinha.Maximum = l; if (l >= 1 && c >= 1) { matriz.RemoverTudo(); matriz = new ListaCruzada(); matriz.MudarDimensao(l, c); dgv.RowCount = l; dgv.ColumnCount = c; exibindoMatriz = true; foreach (DataGridViewRow r in dgv.Rows) { foreach (DataGridViewCell co in r.Cells) { co.Value = 0; } } matriz.Exibir(ref dgv); exibindoMatriz = false; } } }
private void btnLer1_Click(object sender, EventArgs e) { if (dlgArquivo.ShowDialog() == DialogResult.OK) { string arquivo = dlgArquivo.FileName; if (File.Exists(arquivo)) { matrizA = new ListaCruzada(new StreamReader(arquivo)); } else { File.Create(arquivo); } } if (dlgArquivo.ShowDialog() == DialogResult.OK) { string arquivo = dlgArquivo.FileName; if (File.Exists(arquivo)) { matrizB = new ListaCruzada(new StreamReader(arquivo)); } else { File.Create(arquivo); } } matrizA.Exibir(ref dgvA); matrizB.Exibir(ref dgvB); btnMultiplicar.Enabled = true; btnSomar.Enabled = true; }
private void btnMultiplicarMatrizes_Click(object sender, EventArgs e) { //Multiplica a Matriz1 e Matriz2 matrizResultado = matriz1.MultiplicarMatrizes(matriz1, matriz2); matrizResultado.Exibir(ref dgvMatriz3); lMatrizResultado.Enabled = true; }
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; } }