2017-10-09 22:18:51 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using CommonLibrary;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ClientsLibrary.BasicSupport
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class NetClientOnline : UserControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public NetClientOnline()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void NetClientOnline_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-10-15 16:04:28 +08:00
|
|
|
|
|
2017-10-09 22:18:51 +08:00
|
|
|
|
private void ClearControls()
|
|
|
|
|
|
{
|
2017-10-10 21:58:53 +08:00
|
|
|
|
for (int i = MyControls.Count - 1; i >= 0; i--)
|
2017-10-09 22:18:51 +08:00
|
|
|
|
{
|
2017-10-10 21:58:53 +08:00
|
|
|
|
MyControls[i].Dispose();
|
|
|
|
|
|
MyControls.RemoveAt(i);
|
2017-10-09 22:18:51 +08:00
|
|
|
|
}
|
2017-10-14 13:13:02 +08:00
|
|
|
|
|
|
|
|
|
|
Location_Y = 0;
|
2017-10-18 13:46:57 +08:00
|
|
|
|
label2.Text = MyControls.Count.ToString();
|
2017-10-09 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-14 13:13:02 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 清理掉所有的在线信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ClearOnlineClients()
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearControls();
|
|
|
|
|
|
}
|
2017-10-10 21:58:53 +08:00
|
|
|
|
|
|
|
|
|
|
public void ClientOnline(NetAccount account)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (account != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddControl(account);
|
|
|
|
|
|
|
|
|
|
|
|
label2.Text = MyControls.Count.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ClientUpdatePortrait(string userName)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < MyControls.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
MyControls[i].UpdatePortrait(userName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ClinetOffline(string userName)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = -1;
|
|
|
|
|
|
for (int i = 0; i < MyControls.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (MyControls[i].UniqueId == userName)
|
|
|
|
|
|
{
|
|
|
|
|
|
index = i;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
|
{
|
2017-10-11 09:59:58 +08:00
|
|
|
|
int offect = MyControls[index].Height + 4;
|
|
|
|
|
|
Location_Y -= offect;
|
2017-10-10 21:58:53 +08:00
|
|
|
|
MyControls[index].Dispose();
|
|
|
|
|
|
MyControls.RemoveAt(index);
|
|
|
|
|
|
|
|
|
|
|
|
// 重新计算偏移
|
2017-10-11 09:59:58 +08:00
|
|
|
|
|
|
|
|
|
|
for (int i = index; i < MyControls.Count; i++)
|
2017-10-10 21:58:53 +08:00
|
|
|
|
{
|
2017-10-11 09:59:58 +08:00
|
|
|
|
MyControls[i].Location = new Point(2, MyControls[i].Location.Y - offect);
|
2017-10-10 21:58:53 +08:00
|
|
|
|
}
|
2017-10-11 09:59:58 +08:00
|
|
|
|
|
2017-10-10 21:58:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
label2.Text = MyControls.Count.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AddControl(NetAccount account)
|
|
|
|
|
|
{
|
|
|
|
|
|
NetClientItem item = new NetClientItem();
|
|
|
|
|
|
panel1.Controls.Add(item);
|
|
|
|
|
|
// 添加显示
|
|
|
|
|
|
item.SetNetAccount(account);
|
2017-10-11 09:59:58 +08:00
|
|
|
|
item.Location = new Point(2, Location_Y - panel1.VerticalScroll.Value); // 控件的位置
|
|
|
|
|
|
int width = panel1.VerticalScroll.Visible ? Width - 4 - SystemInformation.VerticalScrollBarWidth : Width - 4; // 控件的宽度
|
2017-10-10 21:58:53 +08:00
|
|
|
|
item.Size = new Size(width, item.Size.Height); // 控件的大小
|
|
|
|
|
|
item.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; // 控件随窗口变化的样式
|
|
|
|
|
|
|
|
|
|
|
|
Location_Y += item.Height + 4; // 位置偏移
|
|
|
|
|
|
MyControls.Add(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-09 22:18:51 +08:00
|
|
|
|
public void SetOnlineRender(NetAccount[] accounts)
|
|
|
|
|
|
{
|
|
|
|
|
|
SuspendLayout();
|
|
|
|
|
|
|
|
|
|
|
|
if (accounts != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (accounts.Length > 0 && Width > 20)
|
|
|
|
|
|
{
|
|
|
|
|
|
//添加子控件
|
|
|
|
|
|
foreach (var m in accounts)
|
|
|
|
|
|
{
|
2017-10-10 21:58:53 +08:00
|
|
|
|
AddControl(m);
|
2017-10-09 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-18 13:46:57 +08:00
|
|
|
|
|
2017-10-09 22:18:51 +08:00
|
|
|
|
ResumeLayout();
|
2017-10-18 13:46:57 +08:00
|
|
|
|
|
|
|
|
|
|
label2.Text = MyControls.Count.ToString();
|
2017-10-09 22:18:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-10 21:58:53 +08:00
|
|
|
|
private int Location_Y = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private List<NetClientItem> MyControls = new List<NetClientItem>();
|
2017-10-09 22:18:51 +08:00
|
|
|
|
|
|
|
|
|
|
private void NetClientOnline_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|