95 lines
3.1 KiB
C#
95 lines
3.1 KiB
C#
using qtcnet_client.Properties;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace qtcnet_client.Controls
|
|
{
|
|
public partial class ContactControl : UserControl
|
|
{
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public string UserId { get; set; } = string.Empty; // only for distinction
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
public string Username { get; set; } = "Username";
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
public string TextStatus { get; set; } = "Status";
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
public int Status { get; set; } = 0;
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
public Image ProfilePic { get; set; } = Resources.DefaultPfp;
|
|
|
|
public event EventHandler? OnContactDoubleClicked;
|
|
|
|
bool _isHovering = false;
|
|
public ContactControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ContactControl_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
Graphics g = e.Graphics;
|
|
Rectangle bgBounds = ClientRectangle;
|
|
|
|
Color statusColor = Color.Transparent;
|
|
switch (Status)
|
|
{
|
|
case 0:
|
|
statusColor = Color.LightGray;
|
|
break;
|
|
case 1:
|
|
statusColor = Color.LawnGreen;
|
|
break;
|
|
case 2:
|
|
statusColor = Color.Gold;
|
|
break;
|
|
case 3:
|
|
statusColor = Color.Red;
|
|
break;
|
|
}
|
|
|
|
// draw background based on contacts status
|
|
using LinearGradientBrush lgb = new(bgBounds, statusColor, BackColor, LinearGradientMode.Horizontal);
|
|
g.FillRectangle(lgb, bgBounds);
|
|
}
|
|
|
|
private void ContactControl_Load(object sender, EventArgs e)
|
|
{
|
|
lblUsername.Text = Username;
|
|
lblStatus.Text = $"'{TextStatus}'";
|
|
pbProfilePic.Image = ProfilePic;
|
|
|
|
if (Status == 0)
|
|
{
|
|
lblStatus.Visible = false;
|
|
lblUsername.Location = new(44, 15);
|
|
}
|
|
}
|
|
|
|
private void lblUsername_MouseHover(object sender, EventArgs e)
|
|
{
|
|
if (!_isHovering)
|
|
{
|
|
lblUsername.ForeColor = Color.White;
|
|
_isHovering = true;
|
|
}
|
|
}
|
|
|
|
private void lblUsername_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
if (_isHovering)
|
|
{
|
|
lblUsername.ForeColor = Color.Black;
|
|
_isHovering = false;
|
|
}
|
|
}
|
|
|
|
private void lblUsername_DoubleClick(object sender, EventArgs e) => OnContactDoubleClicked?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|