一个简单的实时聊天界面测试成功,并未对聊天进行记录

This commit is contained in:
dathlin
2017-05-18 17:13:42 +08:00
parent 1b7600a049
commit 6564e044fc
5 changed files with 191 additions and 125 deletions

View File

@@ -37,6 +37,18 @@
this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel_time = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel_time = new System.Windows.Forms.ToolStripStatusLabel();
this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.panel_right = new System.Windows.Forms.Panel(); this.panel_right = new System.Windows.Forms.Panel();
this.label_file_count = new System.Windows.Forms.Label(); this.label_file_count = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label();
@@ -59,20 +71,9 @@
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.label_Announcement = new System.Windows.Forms.Label(); this.label_Announcement = new System.Windows.Forms.Label();
this.panel_left = new System.Windows.Forms.Panel(); this.panel_left = new System.Windows.Forms.Panel();
this.panel_main = new System.Windows.Forms.Panel();
this.label10 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panel_main = new System.Windows.Forms.Panel();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.panel_right.SuspendLayout(); this.panel_right.SuspendLayout();
@@ -154,6 +155,103 @@
this.menuStrip1.TabIndex = 1; this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1"; this.menuStrip1.Text = "menuStrip1";
// //
// 管理员ToolStripMenuItem
//
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem,
this.ToolStripMenuItem,
this.ToolStripMenuItem,
this.ToolStripMenuItem,
this.ToolStripMenuItem});
this.ToolStripMenuItem.Image = global::.Properties.Resources.Team_32xLG;
this.ToolStripMenuItem.Name = "管理员ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(100, 31);
this.ToolStripMenuItem.Text = "管理员";
//
// 更改公告ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "更改公告ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "更改公告";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 日志查看ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "日志查看ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "日志查看";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 账户管理ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "账户管理ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "账户管理";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 远程更新ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "远程更新ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "远程更新";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 注册账号ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "注册账号ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "注册账号";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 设置ToolStripMenuItem
//
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem,
this.ToolStripMenuItem});
this.ToolStripMenuItem.Image = global::.Properties.Resources.PickAxe_32xLG;
this.ToolStripMenuItem.Name = "设置ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(80, 31);
this.ToolStripMenuItem.Text = "设置";
//
// 修改密码ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "修改密码ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "修改密码";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 关于ToolStripMenuItem
//
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem,
this.ToolStripMenuItem,
this.ToolStripMenuItem});
this.ToolStripMenuItem.Image = global::.Properties.Resources.ASCube_32xLG;
this.ToolStripMenuItem.Name = "关于ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(80, 31);
this.ToolStripMenuItem.Text = "关于";
//
// 关于本软件ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "关于本软件ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(184, 32);
this.ToolStripMenuItem.Text = "关于本软件";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 更新日志ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "更新日志ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(184, 32);
this.ToolStripMenuItem.Text = "更新日志";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 版本号说明ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "版本号说明ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(184, 32);
this.ToolStripMenuItem.Text = "版本号说明";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// panel_right // panel_right
// //
this.panel_right.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.panel_right.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
@@ -387,14 +485,6 @@
this.panel_left.Size = new System.Drawing.Size(140, 419); this.panel_left.Size = new System.Drawing.Size(140, 419);
this.panel_left.TabIndex = 4; this.panel_left.TabIndex = 4;
// //
// panel_main
//
this.panel_main.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel_main.Location = new System.Drawing.Point(140, 35);
this.panel_main.Name = "panel_main";
this.panel_main.Size = new System.Drawing.Size(557, 419);
this.panel_main.TabIndex = 5;
//
// label10 // label10
// //
this.label10.Location = new System.Drawing.Point(4, 7); this.label10.Location = new System.Drawing.Point(4, 7);
@@ -403,101 +493,20 @@
this.label10.TabIndex = 0; this.label10.TabIndex = 0;
this.label10.Text = "左侧边栏,不需要可以隐藏"; this.label10.Text = "左侧边栏,不需要可以隐藏";
// //
// 管理员ToolStripMenuItem // panel_main
// //
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.panel_main.Dock = System.Windows.Forms.DockStyle.Fill;
this.ToolStripMenuItem, this.panel_main.Location = new System.Drawing.Point(140, 35);
this.ToolStripMenuItem, this.panel_main.Name = "panel_main";
this.ToolStripMenuItem, this.panel_main.Size = new System.Drawing.Size(557, 419);
this.ToolStripMenuItem, this.panel_main.TabIndex = 5;
this.ToolStripMenuItem});
this.ToolStripMenuItem.Image = global::.Properties.Resources.Team_32xLG;
this.ToolStripMenuItem.Name = "管理员ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(100, 31);
this.ToolStripMenuItem.Text = "管理员";
// //
// 更改公告ToolStripMenuItem // 留言板ToolStripMenuItem
// //
this.ToolStripMenuItem.Name = "更改公告ToolStripMenuItem"; this.ToolStripMenuItem.Name = "留言板ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32); this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "更改公告"; this.ToolStripMenuItem.Text = "留言板";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click); this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 日志查看ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "日志查看ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "日志查看";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 账户管理ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "账户管理ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "账户管理";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 远程更新ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "远程更新ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "远程更新";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 注册账号ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "注册账号ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "注册账号";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 设置ToolStripMenuItem
//
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem});
this.ToolStripMenuItem.Image = global::.Properties.Resources.PickAxe_32xLG;
this.ToolStripMenuItem.Name = "设置ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(80, 31);
this.ToolStripMenuItem.Text = "设置";
//
// 修改密码ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "修改密码ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(164, 32);
this.ToolStripMenuItem.Text = "修改密码";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 关于ToolStripMenuItem
//
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem,
this.ToolStripMenuItem,
this.ToolStripMenuItem});
this.ToolStripMenuItem.Image = global::.Properties.Resources.ASCube_32xLG;
this.ToolStripMenuItem.Name = "关于ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(80, 31);
this.ToolStripMenuItem.Text = "关于";
//
// 关于本软件ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "关于本软件ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(184, 32);
this.ToolStripMenuItem.Text = "关于本软件";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 更新日志ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "更新日志ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(184, 32);
this.ToolStripMenuItem.Text = "更新日志";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// 版本号说明ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "版本号说明ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(184, 32);
this.ToolStripMenuItem.Text = "版本号说明";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
// //
// FormMainWindow // FormMainWindow
// //
@@ -577,6 +586,7 @@
private System.Windows.Forms.Panel panel_left; private System.Windows.Forms.Panel panel_left;
private System.Windows.Forms.Panel panel_main; private System.Windows.Forms.Panel panel_main;
private System.Windows.Forms.Label label10; private System.Windows.Forms.Label label10;
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
} }
} }

View File

@@ -219,6 +219,12 @@ namespace 软件系统客户端模版
Close(); Close();
} }
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
SetShowRenderControl(UIControls_Chat);
UIControls_Chat?.InputFocus();
}
#endregion #endregion
#region #region
@@ -233,7 +239,7 @@ namespace 软件系统客户端模版
net_socket_client.EndPointServer = new System.Net.IPEndPoint( net_socket_client.EndPointServer = new System.Net.IPEndPoint(
System.Net.IPAddress.Parse(UserClient.ServerIp), System.Net.IPAddress.Parse(UserClient.ServerIp),
CommonLibrary.CommonLibrary.Port_Main_Net); CommonLibrary.CommonLibrary.Port_Main_Net);
net_socket_client.ClientAlias = UserClient.UserAccount.UserName; net_socket_client.ClientAlias = $"{UserClient.UserAccount.UserName} [{UserClient.UserAccount.Factory}]";//标记客户端在线的名称
net_socket_client.ClientStart(); net_socket_client.ClientStart();
} }
catch(Exception ex) catch(Exception ex)
@@ -302,7 +308,14 @@ namespace 软件系统客户端模版
UserClient.DateTimeServer = Convert.ToDateTime(object2.Substring(4)); UserClient.DateTimeServer = Convert.ToDateTime(object2.Substring(4));
if (IsHandleCreated) Invoke(new Action(() => if (IsHandleCreated) Invoke(new Action(() =>
{ {
toolStripStatusLabel_time.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm")+$"({net_socket_client.DelayTime}ms)"; toolStripStatusLabel_time.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm") + $"({net_socket_client.DelayTime}ms)";
}));
}
else if (head_code == CommonHeadCode.MultiNetHeadCode.)
{
if (IsHandleCreated) Invoke(new Action(() =>
{
UIControls_Chat?.DealwithReceive(object2.Substring(4));
})); }));
} }
} }
@@ -356,6 +369,12 @@ namespace 软件系统客户端模版
/// </summary> /// </summary>
private UIControls.ShareFilesRender UIControls_Files { get; set; } private UIControls.ShareFilesRender UIControls_Files { get; set; }
/// <summary>
/// 用于聊天的控件
/// </summary>
private UIControls.OnlineChatRender UIControls_Chat { get; set; }
@@ -390,6 +409,18 @@ namespace 软件系统客户端模版
Dock = DockStyle.Fill, Dock = DockStyle.Fill,
}; };
all_main_render.Add(UIControls_Files); all_main_render.Add(UIControls_Files);
UIControls_Chat = new UIControls.OnlineChatRender((m) =>
{
net_socket_client.Send(CommonHeadCode.MultiNetHeadCode. + m);
})
{
Visible = false,
Parent = panel_main,//决定了放在哪个界面显示,此处示例
Dock = DockStyle.Fill,
};
all_main_render.Add(UIControls_Chat);
} }
private void SetShowRenderControl(UserControl control) private void SetShowRenderControl(UserControl control)
@@ -421,10 +452,11 @@ namespace 软件系统客户端模版
UIControls_Files.UpdateFiles(); UIControls_Files.UpdateFiles();
} }
#endregion #endregion
} }
} }

View File

@@ -39,8 +39,10 @@
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.richTextBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.richTextBox1.Location = new System.Drawing.Point(1, 2); this.richTextBox1.Location = new System.Drawing.Point(1, 2);
this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.ReadOnly = true;
this.richTextBox1.Size = new System.Drawing.Size(633, 373); this.richTextBox1.Size = new System.Drawing.Size(633, 373);
this.richTextBox1.TabIndex = 0; this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = ""; this.richTextBox1.Text = "";
@@ -58,6 +60,7 @@
// //
// label1 // label1
// //
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(-1, 381); this.label1.Location = new System.Drawing.Point(-1, 381);

View File

@@ -11,20 +11,40 @@ namespace 软件系统客户端模版.UIControls
{ {
public partial class OnlineChatRender : UserControl public partial class OnlineChatRender : UserControl
{ {
public OnlineChatRender() public OnlineChatRender(Action<string> send)
{ {
InitializeComponent(); InitializeComponent();
SendString = send;
} }
private Action<string> SendString = null;
private void textBox1_KeyDown(object sender, KeyEventArgs e) private void textBox1_KeyDown(object sender, KeyEventArgs e)
{ {
//按下Enter键后进行发送数据到服务器 //按下Enter键后进行发送数据到服务器
if(!string.IsNullOrEmpty(textBox1.Text))
{
if (e.KeyCode == Keys.Enter)
{
SendString?.Invoke(textBox1.Text);
textBox1.Text = "";
}
}
} }
private void OnlineChatRender_Load(object sender, EventArgs e) private void OnlineChatRender_Load(object sender, EventArgs e)
{ {
} }
public void DealwithReceive(string str)
{
richTextBox1.AppendText(str + Environment.NewLine);
}
public void InputFocus()
{
textBox1.Focus();
}
} }
} }

View File

@@ -377,9 +377,8 @@ namespace 软件系统服务端模版
} }
else if (headCode == CommonHeadCode.SimplifyHeadCode.) else if (headCode == CommonHeadCode.SimplifyHeadCode.)
{ {
//更新服务器的账户密码 //更新服务器的账户密码此处使用的是组件自带的验证的方式如果使用SQL数据库另行验证
//此处使用的是组件自带的验证的方式如果使用SQL数据库另行验证 JObject json = JObject.Parse(object2.Substring(4));
Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(object2.Substring(4));
//提取账户,密码 //提取账户,密码
string name = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, ""); string name = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, ""); string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, "");
@@ -519,7 +518,9 @@ namespace 软件系统服务端模版
string headCode = object2.Substring(0, 4); string headCode = object2.Substring(0, 4);
if (headCode == CommonHeadCode.MultiNetHeadCode.) if (headCode == CommonHeadCode.MultiNetHeadCode.)
{ {
string content = headCode + object1._Login_Alias + DateTime.Now.ToString(" yyyy-MM-dd HH:mm:ss") + Environment.NewLine + object2.Substring(4);
//转发所有的客户端,包括发送者
net_socket_server.SendAllClients(content);
} }
} }