RaUI/Source/ryControls/Controls/ctMsgList.cs
2020-11-28 15:03:57 +08:00

159 lines
4.4 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace ryControls
{
/// <summary>
///
/// </summary>
[ToolboxItem(true)]
public partial class CtMsgList : UserControl
{
/// <summary>
/// 消息列表控件
/// </summary>
public CtMsgList()
{
InitializeComponent();
}
int _MaxItemHeight = 0;
/// <summary>
/// 最大高度
/// </summary>
[Category("Appearance"), Description("最大高度")]
public int MaxItemHeight
{
get { return _MaxItemHeight; }
set { _MaxItemHeight = value; }
}
/// <summary>
///
/// </summary>
public void Clear()
{
Controls.Clear();
iTop = 0;
}
int iTop = 0;
/// <summary>
///
/// </summary>
public List<MsgListItem> msg_list = new List<MsgListItem>();
/// <summary>
///
/// </summary>
/// <param name="title"></param>
/// <param name="text"></param>
/// <param name="url"></param>
public void AddItem(string title, string text,string url)
{
this.AutoScrollPosition = new Point(0, 0);
MsgUI item = new MsgUI();
if (_MaxItemHeight >= 0)
item.MaxItemHeight = _MaxItemHeight;
item.AutoSize = true;
item.ShowDateTime = true;
item.Title = title;
item.Text = text.Replace("\r", "").Replace("\n", "");
item.Url = url;
item.Top = iTop;
//item.Height = 123;
item.Width = Width;
Controls.Add(item);
iTop += item.Height;
msg_list.Add(new MsgListItem() { _title = title, _text = text, _url = url });
this.ScrollControlIntoView(item);
}
/// <summary>
///
/// </summary>
/// <param name="title"></param>
/// <param name="text"></param>
public void AddItem(string title, string text)
{
AddItem(title, text, "");
}
/// <summary>
///
/// </summary>
/// <param name="title"></param>
/// <param name="list"></param>
public void AddItem(string title, List<LinkItem> list)
{
AddLinkItem(title, list);
}
/// <summary>
///
/// </summary>
/// <param name="title"></param>
/// <param name="list"></param>
public void AddLinkItem(string title, List<LinkItem> list)
{
Point pos = this.AutoScrollOffset;
this.AutoScrollPosition = new Point(0, 0);
MsgLink item = new MsgLink();
if (_MaxItemHeight >= 0)
item.MaxItemHeight = _MaxItemHeight;
item.AutoSize = true;
item.Title = title;
item.ShowDateTime = true;
for (int i = 0; i < list.Count; i++)
{
item.AddItem(list[i].title.Replace("\r","").Replace("\n",""), list[i].url);
}
item.Top = iTop;
//item.Height = 123;
item.Width = Width;
Controls.Add(item);
iTop += item.Height;
item.BringToFront();
msg_list.Add(new MsgListItem() { _title = title, _list = list });
this.ScrollControlIntoView(item);
}
}
/// <summary>
///
/// </summary>
public class MsgListItem
{
/// <summary>
///
/// </summary>
public string _title = "";
/// <summary>
///
/// </summary>
public string _text="";
/// <summary>
///
/// </summary>
public string _url="";
/// <summary>
///
/// </summary>
public List<LinkItem> _list = new List<LinkItem>();
}
/// <summary>
///
/// </summary>
public class LinkItem
{
/// <summary>
///
/// </summary>
public string title, url;
/// <summary>
///
/// </summary>
/// <param name="title"></param>
/// <param name="url"></param>
public LinkItem(string title, string url)
{
this.title = title;
this.url = url;
}
}
}