C# 自定义弹窗提醒

摘要:
classShaderBox{privateForm_shader;privateForm_parent;private_child;publicShaderBox(Formparent,Formchild){_parent=parent;_child=child;_shader=newForm(){Owner=_parent,Location=_parent.位置,大小=
    classShaderBox
    {
        privateForm _shader;
        privateForm _parent;
        privateForm _child;

        publicShaderBox(Form parent, Form child)
        {
            _parent =parent;
            _child =child;

            _shader = newForm()
            {
                Owner =_parent,
                Location =_parent.Location,
                Size =_parent.Size,
                BackColor =System.Drawing.Color.DimGray,
                //DoubleBuffered = true,
                FormBorderStyle =FormBorderStyle.None,
                Opacity = 0.8D,
                ShowInTaskbar = false,
                StartPosition =FormStartPosition.CenterParent
            };
            _child.Owner =_shader;
            _child.MaximumSize = new System.Drawing.Size(_shader.Width * 80 / 100, _shader.Height * 80 / 100);
            _child.Font =_parent.Font;

            _shader.Shown +=Shader_Shown;
        }

        public voidShow()
        {
            _shader.Show();
            _shader.Location =_parent.Location;
            _shader.BringToFront();
        }

        public voidHide()
        {
            _shader.Hide();
        }

        public voidClose()
        {
            _shader.Close();
        }

        private void Shader_Shown(objectsender, EventArgs e)
        {
            _child.Show();

            int x = _shader.Left + (_shader.Width - _child.Width) / 2;
            int y = _shader.Top + (_shader.Height - _child.Height) / 2;
            _child.Location = newSystem.Drawing.Point(x, y);

            _child.BringToFront();
        }
    }

    classWaitBox : Form
    {
        private Label _lblMsg = null;
        private Timer _timer = null;
        private Label _lblElapsed = null;
        private long _elapsed = 0;

        /// <summary>
        ///消息
        /// </summary>
        public stringMsg
        {
            get =>_lblMsg.Text;
            set => _lblMsg.Text =value;
        }

        publicWaitBox()
        {
            Init();

            FontChanged +=WaitBox_FontChanged;
        }

        private void WaitBox_FontChanged(objectsender, EventArgs e)
        {
            _lblMsg.Font =Font;
        }

        private voidInit()
        {
            Width = 400;
            Height = 70;
            FormBorderStyle =FormBorderStyle.None;
            AutoScaleMode =AutoScaleMode.None;
            ShowInTaskbar = false;
            Shown +=WaitBox_Shown;

            _lblElapsed = newLabel
            {
                Dock =DockStyle.Top,
                TextAlign =ContentAlignment.MiddleRight,
                Text = "",
                ForeColor =Color.Blue,
                Font = newFont(SystemFonts.DefaultFont, FontStyle.Regular),
                Parent = this};
            Controls.Add(_lblElapsed);

            _lblMsg = newLabel
            {
                Dock =DockStyle.Fill,
                TextAlign =ContentAlignment.MiddleCenter,
                Text = "请等待...",
                Parent = this};
            Controls.Add(_lblMsg);

            _timer = newTimer();
            _timer.Interval = 1000;
            _timer.Tick +=_timer_Tick;
        }

        private void WaitBox_Shown(objectsender, EventArgs e)
        {
            _timer.Start();
        }

        private void _timer_Tick(objectsender, EventArgs e)
        {
            _elapsed++;
            _lblElapsed.Text = string.Format("{0}s", _elapsed);
        }
    }

    classWaitHelper
    {
        private static ShaderBox _shaderBox = null;
        private static WaitBox _childBox = null;

        /// <summary>
        ///等待开始
        /// </summary>
        /// <param name="parent">父窗体</param>
        /// <param name="msg">提示消息</param>
        public static void WaitBegin(Form parent, stringmsg)
        {
            _childBox = newWaitBox
            {
                Msg =msg
            };
            _shaderBox = newShaderBox(parent, _childBox);
            _shaderBox.Show();
            Application.DoEvents();
        }
        /// <summary>
        ///实时更新消息
        /// </summary>
        /// <param name="msg"></param>
        public static void WaitUpdate(stringmsg)
        {
            _childBox.Msg =msg;
        }
        /// <summary>
        ///等待结束
        /// </summary>
        public static voidWaitEnd()
        {
            _shaderBox.Close();
            _shaderBox = null;
            _childBox = null;
        }
    }

调用:

        private void button1_Click(objectsender, EventArgs e)
        {
            WaitHelper.WaitBegin(this, "你好,我的朋友!");
            for (int q = 0; q < 100000; q++)
            {
                textBox1.Text =q.ToString();
                Application.DoEvents();//实时响应文本框中的值

                //WaitHelper.WaitUpdate(q.ToString());
}
            WaitHelper.WaitEnd();
        }

效果:

C# 自定义弹窗提醒第1张

免责声明:文章转载自《C# 自定义弹窗提醒》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇超级强大的SVG SMIL animation动画详解Hadoop-2.X HA模式下的FSImage和EditsLog合并过程下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

【Unity】Standard Shader实现分析

记录Unity的标准着色器实现,基于Unity 2017.1版本的代码进行分析。 Standard Shader 文件位于DefaultResourcesExtraStandard.shader 1 //Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT lic...

Cesium深入浅出之3dtiles渲染【转】

引子 接触Cesium一年有余了,期间靠胡吃海塞吸收了很多有用的、没用的知识和技术,感觉有点消化不良,今天终于有时间来梳理一下了。之前一直搞二维的,对三维技术只能算是半路出家,不敢写太深的原理性文章,以免误人子弟,但写写心得还是可以的。我想写一个Cesium深入浅出系列,即将深刻的道理用浅显的语言表述出来,纵观大部分的技术类文章,应该没几个能真正的做到这一...

【整理】unity3d优化总结篇

对项目优化有很多,如:mesh合并 ,减少DrawCall和模型骨骼以及物理计算,合并材质球,优化代码等等,现在继续补上,该内容为本人经验以及网上收集整理,希望大家有更好的优化方法,能够继续跟帖,一起探讨,共同进步。优化:1. 更新不透明贴图的压缩格式为ETC 4bit,因为android市场的手机中的GPU有多种,每家的GPU支持不同的压缩格式,但他们都...

OpenGL编程逐步深入(四)Shaders

OpenGl 中的 Shader在一些中文书籍或资料中都被翻译为“着色器”, 单从字面意思也看不出Shader到底是什么,Shader实际上就是一段代码,用于完成特定功能的一个模块。Shader分为Vertex Shader(顶点着色器)和Pixel Shader(像素着色器)两种,其中Pixel Shader在本文中又被称为Fragment Shade...

RenderSettings 渲染设置

在Edit->RenderSettings里设置 Fog: 激活或不激活 Fog Color:雾的颜色,仅RGB起作用。 Fog Mode:显示方式 Linear线性 Exp指数 Exp2 指数2 Fog Density:雾化的强度 Linear Fog Start:开始距离 Linear Fog End:结束距离 Ambien...

shader 的 nounroll

刚刚解决了一个特别坑的问题。 客户有个需求 需要shader里面 loop 的iterator数量 在运行时确定。z 这样对于里面存在  sample的loop就会被force unroll但因为count不确定 就没法unroll就编译不过了 我发现只有一个方法就是 关掉unroll  我试验了各种 在shader里面用预编译指令 关unroll 的方法...