コード例 #1
0
        /// <summary>
        /// 显示消息
        /// </summary>
        /// <param name="text">消息文本</param>
        /// <param name="style">消息样式。不指定则使用默认样式</param>
        /// <param name="delay">消息停留时长(ms)。为负时使用全局时长</param>
        /// <param name="floating">是否漂浮,不指定则使用全局设置</param>
        /// <param name="point">消息窗显示位置。不指定则智能判定,当由工具栏项(ToolStripItem)弹出时,请指定该参数或使用接收控件的重载</param>
        /// <param name="centerByPoint">是否以point参数为中心进行呈现。为false则是在其附近呈现</param>
        public static void Show(string text, TipStyle style = null, int delay = -1, bool?floating = null, Point?point = null, bool centerByPoint = false)
        {
            var basePoint = point ?? DetemineActive();

            new Thread(arg =>
            {
                LayeredWindow layer = null;
                try
                {
                    layer = new LayeredWindow(CreateTipImage(text ?? string.Empty, style ?? DefaultStyle ?? TipStyle.Gray, out Rectangle contentBounds))
                    {
                        Alpha        = 0,
                        Location     = GetLocation(contentBounds, basePoint, centerByPoint, out var floatDown),
                        MouseThrough = true,
                        TopMost      = true,
                        Tag          = new object[] { delay < 0 ? Delay : delay, floating ?? Floating, floatDown }
                    };
                    layer.Showing += layer_Showing;
                    layer.Closing += layer_Closing;
                    layer.Show();
                }
                finally
                {
                    if (layer != null)
                    {
                        layer.Showing -= layer_Showing;
                        layer.Closing -= layer_Closing;
                        layer.Dispose();
                    }
                }
            })
            {
                IsBackground = true, Name = "T_Showing"
            }.Start();
コード例 #2
0
ファイル: MessageTip.cs プロジェクト: monk8801/MessageTip
        /// <summary>
        /// 显示消息
        /// </summary>
        /// <param name="text">消息文本</param>
        /// <param name="style">消息样式。不指定则使用默认样式</param>
        /// <param name="delay">消息停留时长(ms)。为负时使用全局时长</param>
        /// <param name="floating">是否漂浮,不指定则使用全局设置</param>
        /// <param name="point">消息窗显示位置。不指定则智能判定,当由工具栏项(ToolStripItem)弹出时,请指定该参数或使用接收控件的重载</param>
        /// <param name="centerByPoint">是否以point参数为中心进行呈现。为false则是在其附近呈现</param>
        public static void Show(string text, TipStyle style = null, int delay = -1, bool?floating = null, Point?point = null, bool centerByPoint = false)
        {
            var basePoint = point ?? DetemineActive();

            new Thread(arg =>
            {
                var args           = (object[])arg;
                var tBasePoint     = (Point)args[0];
                var tStyle         = (TipStyle)args[1];
                var tDelay         = (int)args[2];
                var tFloating      = (bool)args[3];
                var tCenterByPoint = (bool)args[4];

                LayeredWindow layer = null;
                try
                {
                    bool floatDown;
                    Rectangle contentBounds;

                    layer = new LayeredWindow(CreateTipImage(text ?? string.Empty, tStyle ?? DefaultStyle ?? TipStyle.Gray, out contentBounds))
                    {
                        Alpha        = 0,
                        Location     = GetLocation(contentBounds, tBasePoint, tCenterByPoint, out floatDown),
                        MouseThrough = true,
                        TopMost      = true,
                        Tag          = new object[] { tDelay, tFloating, floatDown }
                    };
                    layer.Showing += layer_Showing;
                    layer.Closing += layer_Closing;
                    layer.Show();
                }
                finally
                {
                    if (layer != null)
                    {
                        layer.Showing -= layer_Showing;
                        layer.Closing -= layer_Closing;
                        layer.Dispose();
                    }
                }
            })
            {
                IsBackground = true, Name = "T_Showing"
            }.Start(new object[]
            {
                basePoint, style, delay < 0?DefaultDelay:delay, floating ?? Floating, centerByPoint
            });
        }
コード例 #3
0
        /// <summary>
        /// 淡入淡出处理
        /// </summary>
        private static void FadeEffect(LayeredWindow window, bool fadeIn)
        {
            byte      target         = fadeIn ? Byte.MaxValue : Byte.MinValue;
            const int Updateinterval = 10;//动画更新间隔(毫秒)
            int       step           = Fade < Updateinterval ? 0 : (Fade / Updateinterval);

            for (int i = 1; i <= step; i++)
            {
                Thread.Sleep(Updateinterval);

                if (i == step)
                {
                    break;
                }

                var tmp = (double)(fadeIn ? i : (step - i));
                window.Alpha = (byte)(tmp / step * 255);
            }

            window.Alpha = target;
        }