• 大小: 199KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: C#
  • 标签: Winform  提示信息  

资源简介

对应文章地址:https://blog.csdn.net/mazhiyuan1981/article/details/109199984

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TipsWindow
{
    /// 
    /// 说明
    /// 

    /// marc
    public partial class ExplainForm : Formbase
    {
        /// 
        /// 计时器,用于自动关闭窗体
        /// 

        private readonly Timer _timer;
        /// 
        /// 偏移位置
        /// 

        public Point Offset { get; set; } = new Point(5 5);

        /// 
        /// 显示内容
        /// 

        public Control Content { get; }

        /// 
        /// 构造函数
        /// 

        public ExplainForm(Control content)
        {
            InitializeComponent();

            this._timer = new Timer();

            this.Content = content;
            this.ContainerPanel.Controls.Add(content);
            this.Width = content.Width;
            this.Height = content.Height;
        }

        /// 
        /// 设定计时器
        /// 

        /// 自动关闭窗体的间隔时间,单位毫秒
        public void SetAutoCloseTimer(int interval = 5000)
        {
            _timer.Tick += Timer_Tick;
            _timer.Interval = interval;
            _timer.Start();
        }

        /// 
        /// 计时器间隔事件
        /// 

        /// 
        /// 
        private void Timer_Tick(object sender EventArgs e)
        {
            _timer.Stop();
            this.Close();
            this.Dispose();
        }

        /// 
        /// 显示
        /// 

        /// 
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            int x y;

            var screenWidth = Screen.PrimaryScreen.Bounds.Size.Width;
            var screenHeight = Screen.PrimaryScreen.Bounds.Size.Height;

            var controlWidth = ClientRectangle.Width;
            var controlHeight = ClientRectangle.Height;

            if (MousePosition.X + Offset.X + controlWidth < screenWidth)
            {
                x = MousePosition.X + Offset.X;
            }
            else
            {
                x = MousePosition.X - Offset.X - controlWidth;
            }

            if (MousePosition.Y + Offset.Y + controlHeight < screenHeight)
            {
                y = MousePosition.Y + Offset.Y;
            }
            else
            {
                y = MousePosition.Y - Offset.Y - controlHeight;
            }

            Location = new Point(x y);
        }

        /// 
        /// 绘制
        /// 

        /// 
        protected override void OnPaint(PaintEventArgs 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        1136  2020-10-21 11:30  Blog.sln
     目录           0  2020-10-21 11:38  TipsWindow\
     目录           0  2020-10-21 11:26  TipsWindow\bin\
     目录           0  2020-10-21 11:26  TipsWindow\bin\Debug\
     目录           0  2020-10-21 11:31  TipsWindow\bin\Debug\netcoreapp3.1\
     文件         422  2020-10-21 11:34  TipsWindow\bin\Debug\netcoreapp3.1\TipsWindow.deps.json
     文件       12800  2020-10-21 11:43  TipsWindow\bin\Debug\netcoreapp3.1\TipsWindow.dll
     文件      174592  2020-10-21 11:43  TipsWindow\bin\Debug\netcoreapp3.1\TipsWindow.exe
     文件       13988  2020-10-21 11:43  TipsWindow\bin\Debug\netcoreapp3.1\TipsWindow.pdb
     文件         218  2020-10-21 11:31  TipsWindow\bin\Debug\netcoreapp3.1\TipsWindow.runtimeconfig.dev.json
     文件         161  2020-10-21 11:31  TipsWindow\bin\Debug\netcoreapp3.1\TipsWindow.runtimeconfig.json
     目录           0  2020-10-21 11:43  TipsWindow\ExplainControls\
     文件         531  2020-10-21 11:43  TipsWindow\ExplainControls\Example1.cs
     文件        1986  2020-10-21 11:39  TipsWindow\ExplainControls\Example1.Designer.cs
     文件        2816  2020-10-21 11:39  TipsWindow\ExplainControls\Example1.resx
     文件         531  2020-10-21 11:43  TipsWindow\ExplainControls\Example2.cs
     文件        3118  2020-10-21 11:42  TipsWindow\ExplainControls\Example2.Designer.cs
     文件        2816  2020-10-21 11:42  TipsWindow\ExplainControls\Example2.resx
     文件        4406  2020-10-21 11:34  TipsWindow\ExplainForm.cs
     文件        2358  2020-10-21 11:34  TipsWindow\ExplainForm.Designer.cs
     文件        2816  2020-10-21 11:34  TipsWindow\ExplainForm.resx
     文件        1556  2020-10-21 11:34  TipsWindow\Formbase.cs
     文件        2816  2020-10-21 11:34  TipsWindow\Formbase.resx
     文件        2636  2020-10-21 11:38  TipsWindow\MainForm.cs
     文件        3138  2020-10-21 11:36  TipsWindow\MainForm.Designer.cs
     文件        2816  2020-10-21 11:36  TipsWindow\MainForm.resx
     目录           0  2020-10-21 11:26  TipsWindow\obj\
     目录           0  2020-10-21 11:26  TipsWindow\obj\Debug\
     目录           0  2020-10-21 11:43  TipsWindow\obj\Debug\netcoreapp3.1\
     文件         190  2020-10-21 11:26  TipsWindow\obj\Debug\netcoreapp3.1\.NETCoreAppVersion=v3.1.AssemblyAttributes.cs
     文件        1013  2020-10-21 11:26  TipsWindow\obj\Debug\netcoreapp3.1\TipsWindow.AssemblyInfo.cs
............此处省略25个文件信息

评论

共有 条评论