WinFormsPopupAlerts/TooltipAlertRenderer.cs

(开头部分) 8KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

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

namespace WinFormsPopupAlerts
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class TooltipAlertRenderer : Component
    {
        private static Bitmap ErrorIcon = SystemIcons.Error.ToBitmap();
        private static Bitmap WarningIcon = SystemIcons.Warning.ToBitmap();
        private static Bitmap InformationIcon = SystemIcons.Information.ToBitmap();

        private Size maxSize;
        private Size minSize;
        private Padding padding;
        private Padding iconPadding = new Padding(3, 4, 5, 4);

        protected abstract void Draw(System.Drawing.Graphics dc, string title, string text, Rectangle rect, Rectangle titleRect, Rectangle bodyRect, 
            Image img, int iconWidth);

        protected abstract Rectangle GetBodyTextRect(System.Drawing.Graphics dc, string text, Rectangle rect);

        protected abstract Rectangle GetTitleTextRect(System.Drawing.Graphics dc, string text, Rectangle rect);

        protected abstract Size GetCloseButtonSize(Graphics dc, TooltipCloseButtonState buttonState);

        /// <summary>
        /// Drawing content of alert window.
        /// </summary>
        /// <param name="dc">Graphics object of alert window.</param>
        /// <param name="title">Title of alert.</param>
        /// <param name="text">Text of alert.</param>
        /// <param name="icon">Icon of alert.</param>
        /// <param name="customImage">Custom image of alert.</param>
        public virtual void Draw(System.Drawing.Graphics dc, string title, string text, ToolTipIcon icon = ToolTipIcon.None, System.Drawing.Image customImage = null)
        {
            Rectangle titleRect = GetTitleRect(dc, title, text, icon, customImage);
            Rectangle bodyRect = GetBodyRect(dc, title, text, icon, customImage);
            Rectangle rect = GetRect(dc, titleRect, bodyRect, icon, customImage);
            Image img = GetIcon(icon, customImage);
            Draw(dc, title, text, rect, titleRect, bodyRect, img, GetIconSize(icon, customImage).Width);
            // drawing icon
            if (img != null)
                dc.DrawImage(img, new Point(Padding.Left + IconPadding.Left, rect.Height / 2 - (img.Height + IconPadding.Vertical) / 2));
        }

        public virtual System.Drawing.Rectangle GetBodyRect(System.Drawing.Graphics dc, string title, string text, ToolTipIcon icon = ToolTipIcon.None, System.Drawing.Image customImage = null)
        {
            int iconWidth = GetIconSize(icon, customImage).Width;
            int closeButtonWidth = GetCloseButtonSize(dc, TooltipCloseButtonState.Normal).Width;
            int w = Padding.Horizontal + iconWidth + closeButtonWidth;
            Rectangle ret;
            if (string.IsNullOrEmpty(text))
后面还有 156 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。