using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace ryControls
{
///
///
///
public partial class MsgLink : UserControl
{
///
///
///
public MsgLink()
{
InitializeComponent();
timer1.Enabled = true;
Clear();
}
int _MaxItemHeight = 0;
///
/// 最大高度
///
[Category("Appearance"), Description("最大高度")]
public int MaxItemHeight
{
get { return _MaxItemHeight; }
set { _MaxItemHeight = value; pnlContent.MaximumSize = new Size(10000, _MaxItemHeight); }
}
private string _title = "";
///
/// 标题
///
[Category("内容"), Description("标题")]
public string Title
{
get { return _title; }
set { if (ShowDateTime) { lblTitle.Text = value+"("+ ryControls.Pram.Pram.DateDiff(AddTime, DateTime.Now)+")"; } else { lblTitle.Text = value; } _title = value; }
}
///
/// 是否显示时间
///
public bool ShowDateTime { get; set; } = false;
///
/// 添加时间
///
public DateTime AddTime { get; set; } = DateTime.Now;
int iTop = 3;
///
///
///
public void Clear()
{
pnlContent.Controls.Clear();
Height = lblTitle.Height;
pnlContent.Height = 0;
iTop = 6;
}
///
///
///
///
///
public void AddItem(string title,string url)
{
LinkLabel item = new LinkLabel();
item.LinkClicked += new LinkLabelLinkClickedEventHandler(Item_LinkClicked);
item.Text = title;
item.ContextMenuStrip = contextMenuStrip1;
item.AutoSize = false;
item.Tag= url;
item.Top = iTop;
item.Left = 3;
item.Width = pnlContent.Width-20;
toolTip1.SetToolTip(item, title);
item.Anchor =AnchorStyles.Left | AnchorStyles.Right |AnchorStyles.Top;
//item.Height = 123;
pnlContent.Controls.Add(item);
iTop += item.Height+2;
}
void Item_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left)
{
LinkLabel item = (LinkLabel)sender;
System.Diagnostics.Process.Start(item.Tag.ToString());
e.Link.Visited = true;
}
}
catch { }
}
private void 打开页面ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
LinkLabel lnk = (LinkLabel)contextMenuStrip1.SourceControl;
System.Diagnostics.Process.Start(lnk.Tag.ToString());
lnk.LinkVisited = true;
}
catch { }
}
private void 复制文本ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
LinkLabel lnk = (LinkLabel)contextMenuStrip1.SourceControl;
Clipboard.SetText(lnk.Text);
}
catch { }
}
private void Timer1_Tick(object sender, EventArgs e)
{
if (ShowDateTime) { lblTitle.Text = _title + "(" + ryControls.Pram.Pram.DateDiff(AddTime, DateTime.Now) + ")"; }
else
{ lblTitle.Text = _title; }
}
}
}