F_Log.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 
  2. using System;
  3. using System.Windows.Forms;
  4. using PLC_S;
  5. namespace PLC_WF
  6. {
  7. public partial class F_Log : Form, IFormLogShow
  8. {
  9. public F_Log()
  10. {
  11. InitializeComponent();
  12. }
  13. public IShowFormLog ShowFormLog
  14. {
  15. get;
  16. set;
  17. }
  18. private void tsbWarp_Click(object sender, EventArgs e)
  19. {
  20. this.txtLog.WordWrap = !this.txtLog.WordWrap;
  21. if (this.txtLog.WordWrap)
  22. {
  23. this.tsbWarp.Text = "√折行";
  24. }
  25. else
  26. {
  27. this.tsbWarp.Text = " 折行";
  28. }
  29. }
  30. private void tsbClear_Click(object sender, EventArgs e)
  31. {
  32. this.txtLog.Text = null;
  33. }
  34. private int _loglen = 0;
  35. public void ShowLog(string log)
  36. {
  37. if (this.InvokeRequired)
  38. {
  39. this.BeginInvoke(new Action<string>(ShowLog), log);
  40. return;
  41. }
  42. if (_loglen > F_Main.PLC_LOG_LEN)
  43. {
  44. this.txtLog.Text = null;
  45. }
  46. this.txtLog.Text += log + System.Environment.NewLine;
  47. _loglen = this.txtLog.Text.Length;
  48. this.txtLog.SelectionStart = _loglen;
  49. this.txtLog.ScrollToCaret();
  50. }
  51. private void F_Log_FormClosed(object sender, FormClosedEventArgs e)
  52. {
  53. if (ShowFormLog != null)
  54. {
  55. ShowFormLog.FormLogShow = null;
  56. }
  57. }
  58. }
  59. }