private void ButtonExecute_Click(object sender, RoutedEventArgs e) { var calculator = new Calculator(); TextRange textRange = new TextRange(RichTextBoxInput.Document.ContentStart, RichTextBoxInput.Document.ContentEnd); string[] rtbLines = textRange.Text.Split('\n'); List <double[]> result; try { result = calculator.Solve(rtbLines); } catch (Exception) { MessageBox.Show("Некорректные данные!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning); return; } var step = Math.Round((calculator.Tmax - calculator.T) / calculator.N, 2); for (var i = 0; i < calculator.N; i++) { RichTextBoxResult.AppendText($"time = {(i * step):0.00}\n"); for (var j = 0; j < result[i].Length; j++) { RichTextBoxResult.AppendText($"y[{j}] = {result[i][j]}\n"); } RichTextBoxResult.AppendText("\n"); } }
//OutputDataReceivedイベントハンドラ //行が出力されるたびに呼び出される void OutputDataReceived(object sender, DataReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Data)) { // インストール・再インストール時の進捗は表示しない if (e.Data.IndexOf("%") < 0) { Action action = () => { // デバイスをコンボボックスに追加する if (currentCommand == Command.DEVICES || currentCommand == Command.PREDEVICES) { int index = e.Data.IndexOf("\tdevice"); if (index > 0) { ComboBoxDevices.Items.Add(e.Data.Substring(0, index)); ComboBoxDevices.SelectedIndex = 0; } } // 起動時の接続確認は表示しない if (currentCommand != Command.PREDEVICES) { //リッチテキストボックスにフォーカスを移動 RichTextBoxResult.Focus(); //出力された文字列を表示する RichTextBoxResult.AppendText(e.Data + Environment.NewLine); } }; BeginInvoke(action); } } }
//ErrorDataReceivedイベントハンドラ void ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (!string.IsNullOrEmpty(e.Data)) { Action action = () => { //リッチテキストボックスにフォーカスを移動 RichTextBoxResult.Focus(); //エラー出力された文字列を表示する RichTextBoxResult.AppendText(e.Data + Environment.NewLine); }; BeginInvoke(action); } }
private void showCommand(string command) { // 起動時の接続確認は表示しない if (currentCommand != Command.PREDEVICES) { if (RichTextBoxResult.Text.Length == 0) { // 最初のコマンドは先頭で改行しない RichTextBoxResult.AppendText(command + Environment.NewLine); } else { // 2回目以降のコマンドは先頭で改行して前のコマンドとの間を1行開けて見やすくする RichTextBoxResult.AppendText(Environment.NewLine + command + Environment.NewLine); } } }