PanelClientChat.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using ErgometerLibrary;
  8. using ErgometerLibrary.Chat;
  9. namespace ErgometerDoctorApplication
  10. {
  11. public class PanelClientChat : Panel
  12. {
  13. private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
  14. private System.Windows.Forms.Panel panel2;
  15. private System.Windows.Forms.Label label1;
  16. private System.Windows.Forms.Panel panel1;
  17. public System.Windows.Forms.Button button1;
  18. public System.Windows.Forms.RichTextBox richTextBox1;
  19. private System.Windows.Forms.Label label2;
  20. private System.Windows.Forms.Panel panel3;
  21. private System.Windows.Forms.Label connectionLabel;
  22. private int Session { get; }
  23. public PanelClientChat(int session, string name) : base()
  24. {
  25. this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
  26. this.panel2 = new System.Windows.Forms.Panel();
  27. this.connectionLabel = new System.Windows.Forms.Label();
  28. this.label2 = new System.Windows.Forms.Label();
  29. this.label1 = new System.Windows.Forms.Label();
  30. this.panel1 = new System.Windows.Forms.Panel();
  31. this.button1 = new System.Windows.Forms.Button();
  32. this.richTextBox1 = new System.Windows.Forms.RichTextBox();
  33. Session = session;
  34. this.panel3 = new System.Windows.Forms.Panel();
  35. //
  36. // flowLayoutPanel1
  37. //
  38. this.flowLayoutPanel1.AutoSize = true;
  39. this.flowLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly;
  40. this.flowLayoutPanel1.Controls.Add(this.panel2);
  41. this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
  42. this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
  43. this.flowLayoutPanel1.Name = "flowLayoutPanel1";
  44. this.flowLayoutPanel1.Padding = new System.Windows.Forms.Padding(3);
  45. this.flowLayoutPanel1.Size = new System.Drawing.Size(390, 36);
  46. this.flowLayoutPanel1.TabIndex = 0;
  47. this.flowLayoutPanel1.WrapContents = false;
  48. this.flowLayoutPanel1.SizeChanged += new System.EventHandler(this.FlowLayoutPanel1_SizeChanged);
  49. //
  50. // panel2
  51. //
  52. this.panel2.Controls.Add(this.connectionLabel);
  53. this.panel2.Dock = System.Windows.Forms.DockStyle.Left;
  54. this.panel2.Location = new System.Drawing.Point(6, 6);
  55. this.panel2.Name = "panel2";
  56. this.panel2.Size = new System.Drawing.Size(385, 24);
  57. this.panel2.TabIndex = 0;
  58. //
  59. // connectionLabel
  60. //
  61. this.connectionLabel.AutoSize = true;
  62. this.connectionLabel.Font = new System.Drawing.Font("Segoe UI Semibold", 8F, System.Drawing.FontStyle.Bold);
  63. this.connectionLabel.Location = new System.Drawing.Point(4, 4);
  64. this.connectionLabel.Name = "connectionLabel";
  65. this.connectionLabel.Size = new System.Drawing.Size(112, 13);
  66. this.connectionLabel.TabIndex = 0;
  67. this.connectionLabel.Text = "Now connected with: " + name;
  68. //
  69. // label2
  70. //
  71. this.label2.Location = new System.Drawing.Point(0, 0);
  72. this.label2.Name = "label2";
  73. this.label2.Size = new System.Drawing.Size(100, 23);
  74. this.label2.TabIndex = 0;
  75. //
  76. // label1
  77. //
  78. this.label1.Location = new System.Drawing.Point(0, 0);
  79. this.label1.Name = "label1";
  80. this.label1.Size = new System.Drawing.Size(100, 23);
  81. this.label1.TabIndex = 0;
  82. //
  83. // panel1
  84. //
  85. this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
  86. this.panel1.Controls.Add(this.button1);
  87. this.panel1.Controls.Add(this.richTextBox1);
  88. this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
  89. this.panel1.Name = "panel1";
  90. this.panel1.Size = new System.Drawing.Size(400, 100);
  91. this.panel1.TabIndex = 1;
  92. //
  93. // button1
  94. //
  95. this.button1.BackColor = System.Drawing.Color.White;
  96. this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  97. this.button1.Location = new System.Drawing.Point(310, 4);
  98. this.button1.Name = "button1";
  99. this.button1.Size = new System.Drawing.Size(85, 90);
  100. this.button1.TabIndex = 1;
  101. this.button1.Text = "Send";
  102. this.button1.UseVisualStyleBackColor = false;
  103. this.button1.Click += new System.EventHandler(this.button1_Click);
  104. //
  105. // richTextBox1
  106. //
  107. this.richTextBox1.BackColor = System.Drawing.Color.White;
  108. this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  109. this.richTextBox1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  110. this.richTextBox1.Location = new System.Drawing.Point(4, 4);
  111. this.richTextBox1.MaxLength = 250;
  112. this.richTextBox1.Name = "richTextBox1";
  113. this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
  114. this.richTextBox1.Size = new System.Drawing.Size(300, 90);
  115. this.richTextBox1.TabIndex = 0;
  116. this.richTextBox1.Text = "";
  117. this.richTextBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TextBox_KeyDown);
  118. //
  119. // panel3
  120. //
  121. this.panel3.AutoScroll = true;
  122. this.panel3.HorizontalScroll.Enabled = false;
  123. this.panel3.HorizontalScroll.Visible = false;
  124. this.panel3.BackColor = System.Drawing.Color.White;
  125. this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
  126. this.panel3.Controls.Add(this.flowLayoutPanel1);
  127. this.panel3.Location = new System.Drawing.Point(0, 0);
  128. this.panel3.Name = "panel3";
  129. this.panel3.TabIndex = 1;
  130. //
  131. // container
  132. //
  133. this.Controls.Add(this.panel3);
  134. this.Controls.Add(this.panel1);
  135. this.Dock = System.Windows.Forms.DockStyle.Fill;
  136. this.Location = new System.Drawing.Point(0, 0);
  137. this.Name = "container";
  138. this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel3_MouseWheel);
  139. passChatMessage = new ChatDelegate(this.AddChatItem);
  140. }
  141. private void button1_Click(object sender, EventArgs e)
  142. {
  143. if (richTextBox1.TextLength > 1)
  144. {
  145. AddChatItem(new ChatMessage("Doctor", richTextBox1.Text, true));
  146. MainClient.SendNetCommand(new NetCommand(richTextBox1.Text, true, Session));
  147. richTextBox1.ResetText();
  148. }
  149. }
  150. public void AddChatItem(ChatMessage chat)
  151. {
  152. flowLayoutPanel1.Controls.Add(new ChatItem(chat));
  153. }
  154. private void panel3_MouseWheel(object sender, MouseEventArgs e)
  155. {
  156. panel3.Focus();
  157. }
  158. private void FlowLayoutPanel1_SizeChanged(object sender, System.EventArgs e)
  159. {
  160. if (flowLayoutPanel1.Size.Height > panel3.Size.Height)
  161. {
  162. panel2.Width = 375;
  163. flowLayoutPanel1.Width = 380;
  164. panel3.VerticalScroll.Value = panel3.VerticalScroll.Maximum;
  165. }
  166. }
  167. private bool textBoxIsEmpty()
  168. {
  169. string[] text = richTextBox1.Text.Split();
  170. foreach (string s in text)
  171. {
  172. if (s != " ")
  173. {
  174. return false;
  175. }
  176. }
  177. return true;
  178. }
  179. private void TextBox_KeyDown(object sender, KeyEventArgs e)
  180. {
  181. if (e.KeyCode == Keys.Enter)
  182. {
  183. button1_Click(this, new EventArgs());
  184. e.Handled = true;
  185. }
  186. }
  187. public delegate void ChatDelegate(ChatMessage chat);
  188. public ChatDelegate passChatMessage;
  189. }
  190. }