PanelClientChat.cs 8.3 KB

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