FrmMsg.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Tps_LQ_Transmitter.com;
  11. namespace Tps_LQ_Transmitter.views
  12. {
  13. public partial class FrmMsg : Form
  14. {
  15. public FrmMsg()
  16. {
  17. InitializeComponent();
  18. }
  19. private void BtnClear_Click(object sender, EventArgs e)
  20. {
  21. this.richTextBox1.Clear();
  22. }
  23. List<TestMessage> frmMainMsgs;
  24. int index = 1;
  25. public void ShowMsg(List<TestMessage> msgs)
  26. {
  27. if (msgs == null)
  28. return;
  29. frmMainMsgs = msgs;
  30. if (this.Visible == true)
  31. {
  32. if(this.InvokeRequired)
  33. {
  34. this.Invoke(new Action(() => {
  35. if (this.richTextBox1.Text.Length > 1024000)
  36. this.richTextBox1.Clear();
  37. foreach (var item in msgs)
  38. {
  39. richTextBox1.AppendText(string.Format("{0} {1}:{2}{3}", index.ToString(), item.type.ToString(), item.message, Environment.NewLine));
  40. }
  41. index++;
  42. msgs.Clear();
  43. }));
  44. }
  45. else
  46. {
  47. if (this.richTextBox1.Text.Length > 1024000)
  48. this.richTextBox1.Clear();
  49. foreach (var item in msgs)
  50. {
  51. richTextBox1.AppendText(string.Format("{0} {1}:{2}{3}", index.ToString(), item.type.ToString(), item.message, Environment.NewLine));
  52. }
  53. index++;
  54. msgs.Clear();
  55. }
  56. }
  57. }
  58. public void ClearMsg()
  59. {
  60. if (this.InvokeRequired)
  61. {
  62. this.Invoke(new Action(() => {
  63. this.richTextBox1.Clear();
  64. }));
  65. }
  66. else
  67. {
  68. this.richTextBox1.Clear();
  69. }
  70. index = 1;
  71. }
  72. private void FrmMsg_VisibleChanged(object sender, EventArgs e)
  73. {
  74. if(this.Visible)
  75. {
  76. ShowMsg(this.frmMainMsgs);
  77. }
  78. }
  79. }
  80. }