using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ryControls
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MsgUI : UserControl
    {
        /// <summary>
        /// 
        /// </summary>
        public MsgUI()
        {
            InitializeComponent();
            lblText.UpdateInfo();
            timer1.Enabled = true;
        }
        int _MaxItemHeight = 0;
        /// <summary>
        ///最大高度 
        /// </summary>
        [Category("Appearance"), Description("最大高度")]
        public int MaxItemHeight
        {
            get { return _MaxItemHeight; }
            set { _MaxItemHeight = value; panel1.MaximumSize = new Size(10000, _MaxItemHeight); }
        }
        private string _title = "";
        /// <summary>
        /// 标题
        /// </summary>
        [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; }
        }
        /// <summary>
        /// 是否显示时间
        /// </summary>
        public bool ShowDateTime { get; set; } = false;
        /// <summary>
        /// 添加时间
        /// </summary>
        public DateTime AddTime { get; set; } = DateTime.Now;
        /// <summary>
        /// 内容
        /// </summary>
        [Browsable(true), Category("内容"), Description("内容")]
        public override string Text
        {
            get { return lblText.Text; }
            set { lblText.Text = value; lblText.UpdateInfo(); }
        }
        string _url = "";
        /// <summary>
        /// 网址
        /// </summary>
        [Category("内容"), Description("网址")]
        public string Url
        {
            get { return _url; }
            set 
            {
                _url = value;
                if (_url != "")
                {
                    lblTitle.Font = new Font(lblTitle.Font, FontStyle.Underline);
                    lblTitle.Cursor = Cursors.Hand;
                }
                else
                {
                    lblTitle.Font = new Font(lblTitle.Font, FontStyle.Regular);
                    lblTitle.Cursor = Cursors.Default;
                }
            }
        }
        private void MsgUI_Resize(object sender, EventArgs e)
        {
            lblText.UpdateInfo();
        }

        private void LblTitle_Click(object sender, EventArgs e)
        {
            if (_url != "")
            {
                ryCommon.RyFiles.RunFile(_url, "");
            }
        }

        private void MsgUI_Load(object sender, EventArgs e)
        {

        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            if (ShowDateTime) { lblTitle.Text = _title + "(" + ryControls.Pram.Pram.DateDiff(AddTime, DateTime.Now) + ")"; }
            else
            { lblTitle.Text = _title; }
        }
    }
}
