You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.6 KiB

  1. #if NETFX || NETCORE
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Data;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Apewer;
  10. namespace Apewer.Surface
  11. {
  12. /// <summary></summary>
  13. public partial class BlockLog : BaseControl
  14. {
  15. private DataGridView _table = new DataGridView();
  16. private Panel _tipwall = new Panel();
  17. private TextBox _tiptext = new TextBox();
  18. /// <summary></summary>
  19. public BlockLog()
  20. {
  21. BackColor = FormsUtility.GraceBorder;
  22. Padding = new Padding(1);
  23. Controls.Add(_table);
  24. Controls.Add(_tipwall);
  25. _tipwall.Controls.Add(_tiptext);
  26. _tipwall.Visible = false;
  27. _tipwall.Dock = DockStyle.Fill;
  28. _tipwall.Padding = new Padding(40);
  29. _tipwall.BackColor = FormsUtility.White;
  30. _tiptext.Dock = DockStyle.Fill;
  31. _tiptext.Multiline = true;
  32. //_tiptext.ReadOnly = true;
  33. _tiptext.BorderStyle = BorderStyle.None;
  34. _tiptext.BackColor = _tipwall.BackColor;
  35. _tiptext.ScrollBars = ScrollBars.None;
  36. _table.Dock = DockStyle.Fill;
  37. _table.Font = FormsUtility.DefaultFont; ;
  38. _table.ColumnHeadersHeight = 32;
  39. _table.RowHeadersVisible = false;
  40. _table.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  41. _table.MultiSelect = false;
  42. //_table.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  43. _table.BackgroundColor = FormsUtility.White;
  44. _table.GridColor = FormsUtility.GraceBorder;
  45. _table.BorderStyle = BorderStyle.None;
  46. _table.CellBorderStyle = DataGridViewCellBorderStyle.None;
  47. _table.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
  48. _table.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  49. _table.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
  50. _table.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
  51. _table.ReadOnly = true;
  52. _table.AllowUserToAddRows = false;
  53. _table.AllowUserToDeleteRows = false;
  54. _table.AllowUserToOrderColumns = false;
  55. _table.AllowUserToResizeColumns = true;
  56. _table.AllowUserToResizeRows = false;
  57. _table.RowsDefaultCellStyle.BackColor = Color.White;
  58. _table.RowsDefaultCellStyle.NullValue = "";
  59. _table.RowsDefaultCellStyle.SelectionBackColor = FormsUtility.GraceWall;
  60. _table.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.False;
  61. _table.Columns.Add("_clock", "时间");
  62. _table.Columns.Add("_text", "内容");
  63. _table.Columns["_clock"].Width = 150;
  64. _table.Columns["_text"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
  65. _table.ColumnHeadersVisible = false;
  66. _table.CellDoubleClick += Event_Table_DoubleClick;
  67. _tipwall.DoubleClick += Event_TipWall_DoubleClick;
  68. _tiptext.DoubleClick += Event_TipText_DoubleClick;
  69. }
  70. /// <summary></summary>
  71. public new void Dispose()
  72. {
  73. _tipwall.Controls.Clear();
  74. Controls.Clear();
  75. if (_table != null) _table.Dispose();
  76. if (_tiptext != null) _tiptext.Dispose();
  77. if (_tipwall != null) _tipwall.Dispose();
  78. base.Dispose();
  79. }
  80. private void Event_TipText_DoubleClick(object sender, EventArgs e)
  81. {
  82. _tipwall.Visible = false;
  83. _table.Visible = true;
  84. }
  85. private void Event_TipWall_DoubleClick(object sender, EventArgs e)
  86. {
  87. _tipwall.Visible = false;
  88. _table.Visible = true;
  89. }
  90. private void Event_Table_DoubleClick(object sender, DataGridViewCellEventArgs e)
  91. {
  92. if ((e.RowIndex >= 0) && (e.ColumnIndex >= 0))
  93. {
  94. _table.Visible = false;
  95. _tipwall.Visible = true;
  96. _tiptext.Text = _table[e.ColumnIndex, e.RowIndex].Value.ToString();
  97. _tiptext.ForeColor = _table[e.ColumnIndex, e.RowIndex].Style.ForeColor;
  98. }
  99. }
  100. /// <summary></summary>
  101. public void Write(string text = "") { Write(text, ForeColor); }
  102. /// <summary></summary>
  103. public void Blue(string text = "") { Write(text, FormsUtility.Blue); }
  104. /// <summary></summary>
  105. public void Purple(string text = "") { Write(text, FormsUtility.Purple); }
  106. /// <summary></summary>
  107. public void Orange(string text = "") { Write(text, FormsUtility.Orange); }
  108. /// <summary></summary>
  109. public void Black(string text = "") { Write(text, FormsUtility.Black); }
  110. /// <summary></summary>
  111. public void Green(string text = "") { Write(text, FormsUtility.Green); }
  112. /// <summary></summary>
  113. public void Red(string text = "") { Write(text, FormsUtility.Red); }
  114. /// <summary></summary>
  115. public void Gray(string text = "") { Write(text, FormsUtility.GraceLocked); }
  116. /// <summary></summary>
  117. public void Error(string text = "") { Red(text); }
  118. /// <summary></summary>
  119. public void Write(string text, Color color)
  120. {
  121. string t = string.IsNullOrEmpty(text) ? " " : text;
  122. try
  123. {
  124. Invoke(new Invoker(delegate ()
  125. {
  126. int i = _table.Rows.Add(ClockUtility.LucidNow, t);
  127. var c = (color == null) ? FormsUtility.Black : color;
  128. _table.Rows[i].Height = 24;
  129. _table.Rows[i].Cells[0].Style.Padding = new Padding(6, 0, 4, 0);
  130. _table.Rows[i].Cells[0].Style.ForeColor = FormsUtility.GraceLocked;
  131. _table.Rows[i].Cells[0].Style.SelectionForeColor = FormsUtility.GraceLocked;
  132. _table.Rows[i].Cells[1].Style.ForeColor = c;
  133. _table.Rows[i].Cells[1].Style.SelectionForeColor = c;
  134. _table.CurrentCell = _table[0, i];
  135. }));
  136. }
  137. catch { }
  138. }
  139. /// <summary></summary>
  140. public void Clean()
  141. {
  142. _table.Rows.Clear();
  143. }
  144. /// <summary></summary>
  145. public void Clear()
  146. {
  147. Clean();
  148. }
  149. /// <summary></summary>
  150. public void ShowMilli()
  151. {
  152. _table.Columns["_clock"].Width = 160;
  153. }
  154. }
  155. }
  156. #endif