103 lines
3.0 KiB
C#
103 lines
3.0 KiB
C#
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;
|
|
using System.Threading;
|
|
|
|
namespace ClientsLibrary.BasicSupport
|
|
{
|
|
public partial class NetClientItem : UserControl
|
|
{
|
|
public NetClientItem()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void NetClientItem_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
if (m_NetAccount != null)
|
|
{
|
|
// 绘制角色名称
|
|
if (m_NetAccount.Roles?.Length > 0)
|
|
{
|
|
int m_x = 45;
|
|
int m_y = 20;
|
|
|
|
for (int i = 0; i < m_NetAccount.Roles.Length; i++)
|
|
{
|
|
SizeF m_size = e.Graphics.MeasureString(m_NetAccount.Roles[i], Font);
|
|
e.Graphics.FillRectangle(Brushes.LightBlue, m_x, m_y - 2, m_size.Width, m_size.Height);
|
|
e.Graphics.DrawString(m_NetAccount.Roles[i], Font, Brushes.Blue, new Point(m_x, m_y));
|
|
m_x += (int)m_size.Width + 3;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void SetNetAccount(NetAccount account)
|
|
{
|
|
m_NetAccount = account;
|
|
// 加载头像,显示信息
|
|
label1.Text = (string.IsNullOrEmpty(account.Alias) ? account.UserName : account.Alias) + $" ({account.Factory})";
|
|
|
|
ThreadPool.QueueUserWorkItem(ThreadPoolLoadPortrait, null);
|
|
}
|
|
|
|
|
|
private void ThreadPoolLoadPortrait(object obj)
|
|
{
|
|
// 向服务器请求小头像
|
|
if(m_NetAccount!=null)
|
|
{
|
|
try
|
|
{
|
|
System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
|
|
|
HslCommunication.OperateResult result = UserClient.Net_File_Client.DownloadFile(
|
|
PortraitSupport.SmallPortrait,
|
|
"Files",
|
|
"Portrait",
|
|
m_NetAccount.UserName,
|
|
null,
|
|
ms
|
|
);
|
|
if (result.IsSuccess)
|
|
{
|
|
Bitmap bitmap = new Bitmap(ms);
|
|
pictureBox1.Image = bitmap;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(result.Message);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private NetAccount m_NetAccount;
|
|
|
|
private void NetClientItem_MouseEnter(object sender, EventArgs e)
|
|
{
|
|
BackColor = Color.AliceBlue;
|
|
}
|
|
|
|
private void NetClientItem_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
BackColor = SystemColors.Control;
|
|
}
|
|
|
|
|
|
}
|
|
}
|