Ejemplo n.º 1
0
        /// <summary>
        /// set the html of the label, resize the tooltip
        /// </summary>
        public void SetText(string content, int minimumWidth = 200)
        {
            if (Visible)
            {
                Cloak();
            }

            var screen = Npp.NppScreen;

            _labelContent.SetNeededSize(content, minimumWidth, screen.WorkingArea.Width / 2 - 20);

            _panel.ContentPanel.Size = _labelContent.Size;
            Size = new Size(_panel.ContentPanel.Width + 10, Math.Min(_labelContent.Height, screen.WorkingArea.Height / 2 - 10) + 10);

            // Too tall?
            if (_labelContent.Height > (screen.WorkingArea.Height / 2 - 10))
            {
                Width = Width + 10; // add scrollbar width
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new notification, to be displayed with Show() later
        /// </summary>
        public YamuiNotification(string htmlTitle, string htmlMessage, int duration, Screen screenToUse = null, int formMinWidth = 0, int formMaxWidth = 0, int formMaxHeight = 0, EventHandler <HtmlLinkClickedEventArgs> onLinkClicked = null) : base(YamuiFormOption.IsPopup | YamuiFormOption.WithDropShadow | YamuiFormOption.AlwaysOnTop | YamuiFormOption.DontShowInAltTab | YamuiFormOption.DontActivateOnShow)
        {
            // close all notif button
            CloseAllBox     = true;
            OnCloseAllNotif = CloseAllNotif;
            Movable         = false;
            Resizable       = false;
            ShowIcon        = false;
            ShowInTaskbar   = false;

            InitializeComponent();

            // correct input if needed
            _screen = screenToUse ?? Screen.PrimaryScreen;
            if (formMaxWidth == 0)
            {
                formMaxWidth = _screen.WorkingArea.Width - 20;
            }
            if (formMaxHeight == 0)
            {
                formMaxHeight = _screen.WorkingArea.Height - 20;
            }
            if (formMinWidth == 0)
            {
                formMinWidth = 300;
            }

            // Set title, it will define a new minimum width for the message box
            titleLabel.Location = new Point(5, 5);
            var space = FormButtonWidth + BorderWidth * 2 + titleLabel.Location.X + 5;

            titleLabel.SetNeededSize(htmlTitle, formMinWidth - space, formMaxWidth - space, true);
            formMinWidth = formMinWidth.ClampMin(titleLabel.Width + space);
            var newPadding = Padding;

            newPadding.Bottom = newPadding.Bottom + (duration > 0 ? 8 : 0);
            newPadding.Top    = titleLabel.Height + 10;
            Padding           = newPadding;

            // set content label
            space = Padding.Left + Padding.Right;
            contentLabel.SetNeededSize(htmlMessage, formMinWidth - space, formMaxWidth - space, true);
            if (onLinkClicked != null)
            {
                contentLabel.LinkClicked += onLinkClicked;
            }

            // set form size
            Size        = new Size(contentLabel.Width + space, (Padding.Top + Padding.Bottom + contentLabel.Height).ClampMax(formMaxHeight));
            MinimumSize = Size;


            // do we need to animate a panel on the bottom to visualise time left?
            if (duration > 0)
            {
                _duration          = duration * 1000;
                ProgressPercent    = 100;
                _closingTransition = new Transition(new TransitionType_Linear(_duration));
                _closingTransition.add(this, "ProgressPercent", 0);
                _closingTransition.TransitionCompletedEvent += (o, args) => { Close(); };
            }
            else
            {
                _duration = 0;
            }
        }