Example #1
0
        /// <summary>
        /// 显示一个定时标签消息框。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="parameters">设置参数。</param>
        public static void ShowLabel(this Control owner, MessageLabelParameters parameters)
        {
            if (owner != null && owner.InvokeRequired)
            {
                owner.Invoke(new Action <Control, MessageLabelParameters>(ShowLabel), owner, parameters);
            }
            else
            {
                if (owner == null)
                {
                    new MessageLabelForm(null, parameters).Show();
                    return;
                }
                var waitingTask = owner as IWaitingTask;
                var ownerForm   = waitingTask == null?owner.FindForm() : waitingTask.CallerForm;

                if (ownerForm == null)
                {
                    return;
                }

                if (ownerForm.InvokeRequired)
                {
                    new MessageLabelForm(null, parameters).Show();
                }
                else
                {
                    ownerForm.Activate();
                    new MessageLabelForm(owner, parameters).Show(ownerForm);
                    ownerForm.Activate();
                }
            }
        }
Example #2
0
        /// <summary>
        /// 显示一个定时标签消息框。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="content">消息内容。</param>
        public static void ShowLabel(this Control owner, string content)
        {
            var parameters = new MessageLabelParameters();

            parameters.Content.Text = content;
            Msg.ShowLabel(owner, parameters);
        }
Example #3
0
        /// <summary>
        /// 显示一个定时标签消息框。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="content">消息内容。</param>
        /// <param name="messageBoxIcon">显示的图标。</param>
        public static void ShowLabel(this Control owner, string content, MessageBoxIconEx messageBoxIcon)
        {
            var parameters = new MessageLabelParameters();

            parameters.Content.Text        = content;
            parameters.Icon.MessageBoxIcon = messageBoxIcon;
            Msg.ShowLabel(owner, parameters);
        }
Example #4
0
        /// <summary>
        /// 显示一个定时标签消息框。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="content">消息内容。</param>
        /// <param name="seconds">定时的秒数。</param>
        public static void ShowLabel(this Control owner, string content, int seconds)
        {
            var parameters = new MessageLabelParameters();

            parameters.Content.Text     = content;
            parameters.CloseMillisecond = seconds * 1000;
            Msg.ShowLabel(owner, parameters);
        }
Example #5
0
        /// <summary>
        /// 显示一个定时标签消息框。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="content">消息内容。</param>
        /// <param name="alignment">对齐方式。</param>
        /// <param name="isAlignmentScreen">是否对齐于桌面。</param>
        public static void ShowLabel(this Control owner, string content, ContentAlignment alignment, bool isAlignmentScreen = false)
        {
            var parameters = new MessageLabelParameters();

            parameters.Content.Text      = content;
            parameters.Alignment         = alignment;
            parameters.IsAlignmentScreen = isAlignmentScreen;
            Msg.ShowLabel(owner, parameters);
        }
Example #6
0
        internal MessageLabelForm(Control owner, MessageLabelParameters parameters)
        {
            this.InitializeComponent(parameters);

            var size = this.RectangleToScreen(this.DisplayRectangle).Size;

            this.AutoSize        = false;
            lbl_Content.AutoSize = false;
            this.Size            = size;
            if (parameters.Point.HasValue)
            {
                this.Location = parameters.Point.Value;
            }
            else
            {
                if (owner == null)
                {
                    owner = System.Windows.Forms.Form.ActiveForm;
                }
                if (owner == null)
                {
                    this.StartPosition = FormStartPosition.CenterScreen;
                }
                else
                {
                    Form ownerForm = owner.FindForm();
                    if (ownerForm.ParentForm != null)
                    {
                        ownerForm = ownerForm.ParentForm;
                    }
                    if (ownerForm.MdiParent != null)
                    {
                        ownerForm = ownerForm.MdiParent;
                    }

                    this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;

                    if (parameters.IsAlignmentScreen)
                    {
                        this.Location = this.GetPoint(Screen.GetWorkingArea(ownerForm), parameters.Alignment);
                    }
                    else
                    {
                        this.Location = this.GetPoint(ownerForm.RectangleToScreen(ownerForm.ClientRectangle), parameters.Alignment);
                    }
                }
            }
            this._closeEnd       = parameters.CloseMillisecond;
            this._timer.Interval = 100;
            this._timer.Tick    += new EventHandler(timer_Tick);
        }
Example #7
0
        private void InitializeComponent(MessageLabelParameters parameters)
        {
            this.components = new System.ComponentModel.Container();
            var form      = parameters.Form;
            var content   = parameters.Content;
            var icon      = parameters.Icon;
            var errorIcon = icon.MessageBoxIcon == MessageBoxIconEx.Error;

            this.lbl_Content   = new Label();
            this.panelControl1 = new Panel2();
#if DEVEXPRESS
            ((System.ComponentModel.ISupportInitialize)(this.panelControl1)).BeginInit();
#endif
            this.panelControl1.SuspendLayout();
            this.SuspendLayout();
            //
            // lbl_Content
            //
            this.lbl_Content.AutoEllipsis = true;
            this.lbl_Content.AutoSize     = true;
            this.lbl_Content.Dock         = System.Windows.Forms.DockStyle.Fill;

            this.lbl_Content.Font = content.Font == null
                ? new System.Drawing.Font("新宋体", 9F, System.Drawing.FontStyle.Bold)
                : content.Font;

            this.lbl_Content.ForeColor = content.ForeColor.HasValue
                ? content.ForeColor.Value
                : (errorIcon ? Color.FromArgb(170, 57, 57) : Color.FromArgb(45, 68, 136));

            if (content.BackColor.HasValue)
            {
                this.lbl_Content.BackColor = content.BackColor.Value;
            }

            this.lbl_Content.Location = new System.Drawing.Point(58, 10);
            this.lbl_Content.Name     = "lbl_Content";
            this.lbl_Content.Size     = new System.Drawing.Size(57, 12);
            this.lbl_Content.TabIndex = 2;
            this.lbl_Content.Text     = content.Text;
            if (parameters.ClickClosed)
            {
                this.lbl_Content.Click += new System.EventHandler(this.Close_Click);
            }
            this.lbl_Content.Padding = new Padding(0, 10, 0, 10);
            //
            // panelControl1
            //
            this.panelControl1.AutoSize = true;
            this.panelControl1.Controls.Add(this.lbl_Content);
            this.panelControl1.Dock     = System.Windows.Forms.DockStyle.Fill;
            this.panelControl1.Location = new System.Drawing.Point(0, 0);
            this.panelControl1.Name     = "panelControl1";
            this.panelControl1.Padding  = new System.Windows.Forms.Padding(8);
            this.panelControl1.Size     = new System.Drawing.Size(300, 300);
            this.panelControl1.TabIndex = 3;
#if DEVEXPRESS
            this.panelControl1.BorderStyle            = DevExpress.XtraEditors.Controls.BorderStyles.Simple;
            this.panelControl1.Appearance.BorderColor = errorIcon ? Color.FromArgb(170, 57, 57) : Color.FromArgb(136, 176, 228);
#else
            this.panelControl1.BorderStyle = BorderStyle.FixedSingle;
#endif
            if (parameters.ClickClosed)
            {
                this.panelControl1.Click += new System.EventHandler(this.Close_Click);
            }
            if (icon.Image != null)
            {
                this.lbl_Content.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
                this.lbl_ICON = new System.Windows.Forms.Label();
                //
                // lbl_ICON
                //
                this.lbl_ICON.Dock     = System.Windows.Forms.DockStyle.Left;
                this.lbl_ICON.Location = new System.Drawing.Point(10, 10);
                this.lbl_ICON.Name     = "lbl_ICON";
                this.lbl_ICON.Size     = new System.Drawing.Size(48, 280);
                this.lbl_ICON.TabIndex = 3;
                this.lbl_ICON.Image    = icon.Image;
                if (parameters.ClickClosed)
                {
                    this.lbl_ICON.Click += new System.EventHandler(this.Close_Click);
                }
                this.lbl_Content.Padding = new Padding(4, 0, 0, 0);

                this.panelControl1.Controls.Add(this.lbl_ICON);
            }
            else
            {
                this.lbl_Content.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            }
            //
            // MessageLabelForm
            //
            this.Text = form.Text;
            if (form.Font != null)
            {
                this.Font = form.Font;
            }
            if (form.ForeColor.HasValue)
            {
                this.ForeColor = form.ForeColor.Value;
            }
            if (form.BackColor.HasValue)
            {
                this.BackColor = form.BackColor.Value;
            }

            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
            this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
            this.AutoSize            = true;
            this.AutoSizeMode        = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.ClientSize          = new System.Drawing.Size(300, 300);
            this.Controls.Add(this.panelControl1);
            this.DoubleBuffered  = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MaximizeBox     = false;
            this.MinimizeBox     = false;
            this.Opacity         = 0d;
            this.Name            = "MessageLabelForm";
            this.ShowIcon        = false;
            this.ShowInTaskbar   = false;

            this.TopMost = true;
            if (icon.Image != null)
            {
                this.MinimumSize = new System.Drawing.Size(0, 56);
            }

            this.MaximumSize = new Size(800, 600);
#if DEVEXPRESS
            ((System.ComponentModel.ISupportInitialize)(this.panelControl1)).EndInit();
#endif
            this.panelControl1.ResumeLayout(false);
            this.panelControl1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();
        }
Example #8
0
        /// <summary>
        /// 显示一个定时标签消息框。
        /// </summary>
        /// <param name="owner">控件拥有者。</param>
        /// <param name="parameters">设置参数。</param>
        public static void ShowLabel(this Control owner, MessageLabelParameters parameters)
        {
            if (owner != null && owner.InvokeRequired)
            {
                owner.Invoke(new Action<Control, MessageLabelParameters>(ShowLabel), owner, parameters);
            }
            else
            {
                if (owner == null)
                {
                    new MessageLabelForm(null, parameters).Show();
                    return;
                }
                var waitingTask = owner as IWaitingTask;
                var ownerForm = waitingTask == null ? owner.FindForm() : waitingTask.CallerForm;
                if (ownerForm == null)
                    return;

                if (ownerForm.InvokeRequired) new MessageLabelForm(null, parameters).Show();
                else
                {
                    ownerForm.Activate();
                    new MessageLabelForm(owner, parameters).Show(ownerForm);
                    ownerForm.Activate();
                }
            }
        }
Example #9
0
 /// <summary>
 /// 显示一个定时标签消息框。
 /// </summary>
 /// <param name="owner">控件拥有者。</param>
 /// <param name="content">消息内容。</param>
 /// <param name="messageBoxIcon">显示的图标。</param>
 public static void ShowLabel(this Control owner, string content, MessageBoxIconEx messageBoxIcon)
 {
     var parameters = new MessageLabelParameters();
     parameters.Content.Text = content;
     parameters.Icon.MessageBoxIcon = messageBoxIcon;
     Msg.ShowLabel(owner, parameters);
 }
Example #10
0
 /// <summary>
 /// 显示一个定时标签消息框。
 /// </summary>
 /// <param name="owner">控件拥有者。</param>
 /// <param name="content">消息内容。</param>
 /// <param name="seconds">定时的秒数。</param>
 public static void ShowLabel(this Control owner, string content, int seconds)
 {
     var parameters = new MessageLabelParameters();
     parameters.Content.Text = content;
     parameters.CloseMillisecond = seconds * 1000;
     Msg.ShowLabel(owner, parameters);
 }
Example #11
0
 /// <summary>
 /// 显示一个定时标签消息框。
 /// </summary>
 /// <param name="owner">控件拥有者。</param>
 /// <param name="content">消息内容。</param>
 /// <param name="alignment">对齐方式。</param>
 /// <param name="isAlignmentScreen">是否对齐于桌面。</param>
 public static void ShowLabel(this Control owner, string content, ContentAlignment alignment, bool isAlignmentScreen = false)
 {
     var parameters = new MessageLabelParameters();
     parameters.Content.Text = content;
     parameters.Alignment = alignment;
     parameters.IsAlignmentScreen = isAlignmentScreen;
     Msg.ShowLabel(owner, parameters);
 }
Example #12
0
 /// <summary>
 /// 显示一个定时标签消息框。
 /// </summary>
 /// <param name="owner">控件拥有者。</param>
 /// <param name="content">消息内容。</param>
 public static void ShowLabel(this Control owner, string content)
 {
     var parameters = new MessageLabelParameters();
     parameters.Content.Text = content;
     Msg.ShowLabel(owner, parameters);
 }