diff --git a/CommonControls/BaseForm.cs b/CommonControls/BaseForm.cs index 9570e4d..1fc9d1e 100644 --- a/CommonControls/BaseForm.cs +++ b/CommonControls/BaseForm.cs @@ -7,7 +7,9 @@ using System.Net; using System.Net.Sockets; using System.Text; +using System.Threading.Tasks; using System.Windows.Forms; +using static System.Windows.Forms.LinkLabel; namespace Modbus.Common { @@ -597,6 +599,25 @@ private void buttonPauseLog_Click(object sender, EventArgs e) buttonPauseLog.Text = _logPaused ? "Resume" : "Pause"; } + private async void buttonSaveLog_ClickAsync(object sender, EventArgs e) + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.FileName = "ModbusLog"; + saveFileDialog.OverwritePrompt = true; + saveFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; + saveFileDialog.DefaultExt = "txt"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + using (StreamWriter writer = new StreamWriter(saveFileDialog.FileName, append: true)) + { + foreach (string line in listBoxCommLog.Items) + { + await writer.WriteLineAsync(line); + } + } + } + } + protected void DriverIncommingData(byte[] data, int len) { if (_logPaused) @@ -632,7 +653,7 @@ protected void AppendLog(String log) var tmpStr = ">" + now.ToLongTimeString() + ": " + log; listBoxCommLog.Items.Add(tmpStr); listBoxCommLog.SelectedIndex = listBoxCommLog.Items.Count - 1; - listBoxCommLog.SelectedIndex = -1; + //listBoxCommLog.SelectedIndex = -1; } #endregion @@ -737,5 +758,6 @@ private void donate_Click(object sender, EventArgs e) string url = "https://www.buymeacoffee.com/r4K2HIB"; System.Diagnostics.Process.Start(url); } + } } diff --git a/CommonControls/BaseForm.designer.cs b/CommonControls/BaseForm.designer.cs index 8119eba..c7c7e22 100644 --- a/CommonControls/BaseForm.designer.cs +++ b/CommonControls/BaseForm.designer.cs @@ -32,6 +32,7 @@ protected void InitializeComponent() Modbus.Common.DataTab dataTab2; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BaseForm)); this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.buttonSave = new System.Windows.Forms.Button(); this.buttonPauseLog = new System.Windows.Forms.Button(); this.listBoxCommLog = new System.Windows.Forms.ListBox(); this.buttonClear = new System.Windows.Forms.Button(); @@ -116,6 +117,7 @@ protected void InitializeComponent() // // groupBox4 // + this.groupBox4.Controls.Add(this.buttonSave); this.groupBox4.Controls.Add(this.buttonPauseLog); this.groupBox4.Controls.Add(this.listBoxCommLog); this.groupBox4.Controls.Add(this.buttonClear); @@ -126,9 +128,18 @@ protected void InitializeComponent() this.groupBox4.TabStop = false; this.groupBox4.Text = "Communication Log"; // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(760, 19); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(86, 28); + this.buttonSave.TabIndex = 26; + this.buttonSave.Text = "Save"; + this.buttonSave.Click += new System.EventHandler(this.buttonSaveLog_ClickAsync); + // // buttonPauseLog // - this.buttonPauseLog.Location = new System.Drawing.Point(660, 19); + this.buttonPauseLog.Location = new System.Drawing.Point(576, 19); this.buttonPauseLog.Name = "buttonPauseLog"; this.buttonPauseLog.Size = new System.Drawing.Size(86, 28); this.buttonPauseLog.TabIndex = 25; @@ -148,7 +159,7 @@ protected void InitializeComponent() // // buttonClear // - this.buttonClear.Location = new System.Drawing.Point(752, 19); + this.buttonClear.Location = new System.Drawing.Point(668, 19); this.buttonClear.Name = "buttonClear"; this.buttonClear.Size = new System.Drawing.Size(86, 28); this.buttonClear.TabIndex = 24; @@ -662,5 +673,6 @@ protected void InitializeComponent() private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.Button donate; + protected System.Windows.Forms.Button buttonSave; } } \ No newline at end of file