balloonhelper.cs

来自「破解的飞信源代码」· CS 代码 · 共 133 行

CS
133
字号
namespace Imps.Client.Pc.Utils
{
    using Imps.Client.Pc.Controls;
    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public class BalloonHelper
    {
        private static ImpsBalloon _balloon;

        private BalloonHelper()
        {
        }

        public static void RemoveAll()
        {
            if (_balloon != null)
            {
                _balloon.Close();
                _balloon.Dispose();
                _balloon = null;
            }
        }

        public static void ShowBallon(Control c, string message)
        {
            ShowBallon(c, message, -1);
        }

        public static void ShowBallon(Control c, string message, Point location)
        {
            ShowBallon(c, message, string.Empty, location);
        }

        public static void ShowBallon(Control c, string message, int duration)
        {
            ShowBallon(c, message, string.Empty, duration);
        }

        public static void ShowBallon(Control c, string message, string title, Point location)
        {
            ShowBallon(c, message, title, 1, location);
        }

        public static void ShowBallon(Control c, string message, string title, int duration)
        {
            ShowBallon(c, message, title, 1, duration);
        }

        public static void ShowBallon(Control c, string message, string title, ToolTipIcon icon)
        {
            ShowBallon(c, message, title, icon, Point.Empty, -1);
        }

        public static void ShowBallon(Control c, string message, string title, ToolTipIcon icon, Point location)
        {
            ShowBallon(c, message, title, icon, location, -1);
        }

        public static void ShowBallon(Control c, string message, string title, ToolTipIcon icon, int duration)
        {
            ShowBallon(c, message, title, icon, Point.Empty, duration);
        }

        public static void ShowBallon(Control c, string message, string title, ToolTipIcon icon, Point location, int duration)
        {
            RemoveAll();
            _balloon = new ImpsBalloon();
            _balloon.ParentControl = c;
            _balloon.Title = title;
            _balloon.Text = message;
            if (duration > 0)
            {
                _balloon.Duration = duration;
            }
            switch (icon)
            {
                case 0:
                    _balloon.Icon = BalloonIcon.None;
                    break;

                case 1:
                    _balloon.Icon = BalloonIcon.Info;
                    break;

                case 2:
                    _balloon.Icon = BalloonIcon.Warning;
                    break;

                case 3:
                    _balloon.Icon = BalloonIcon.Error;
                    break;
            }
            _balloon.Alignment = BalloonAlignment.BottomMiddle;
            _balloon.IsPositionAbsolute = true;
            _balloon.IsStemCentered = true;
            try
            {
                _balloon.Show();
            }
            catch (Exception)
            {
            }
        }

        public static void ShowInputErrorBallon(Control c, string message)
        {
            ShowInputErrorBallon(c, message, string.Empty, 0x7d0);
        }

        public static void ShowInputErrorBallon(Control c, string message, string title)
        {
            ShowInputErrorBallon(c, message, title, 0x7d0);
        }

        public static void ShowInputErrorBallon(Control c, string message, string title, int duration)
        {
            if (c is TextBoxBase)
            {
                ((TextBoxBase) c).SelectAll();
            }
            else if (c is ComboBox)
            {
                ((ComboBox) c).SelectAll();
            }
            c.Focus();
            ShowBallon(c, message, title, 3, duration);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?