using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace ryControls { /// /// /// [ToolboxItem(true)] public partial class CtMsgList : UserControl { /// /// 消息列表控件 /// public CtMsgList() { InitializeComponent(); } int _MaxItemHeight = 0; /// /// 最大高度 /// [Category("Appearance"), Description("最大高度")] public int MaxItemHeight { get { return _MaxItemHeight; } set { _MaxItemHeight = value; } } /// /// /// public void Clear() { Controls.Clear(); iTop = 0; } int iTop = 0; /// /// /// public List msg_list = new List(); /// /// /// /// /// /// 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); } /// /// /// /// /// public void AddItem(string title, string text) { AddItem(title, text, ""); } /// /// /// /// /// public void AddItem(string title, List list) { AddLinkItem(title, list); } /// /// /// /// /// public void AddLinkItem(string title, List 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); } } /// /// /// public class MsgListItem { /// /// /// public string _title = ""; /// /// /// public string _text=""; /// /// /// public string _url=""; /// /// /// public List _list = new List(); } /// /// /// public class LinkItem { /// /// /// public string title, url; /// /// /// /// /// public LinkItem(string title, string url) { this.title = title; this.url = url; } } }