C# 当录入错误的时候,右下角弹窗提示错误信息

做一个textbox录入数字的判断,当录入不是数字的时候右下角弹窗提示

右下角弹窗提示

主要代码如下:判断是否为数字的代码:

   private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {  
            if(e.KeyChar==13)
            {
                string num = this.textBox1.Text;
                try
                {
                    int num2 = Convert.ToInt16(num);
                }
                catch
                {
                    SetMessages(num); //调用事件并将判断结果传回弹窗;
                }
            }
        }

 private void SetMessages(string num)  //调用弹窗的事件
        {
            Message msg = new Message();
            msg.GetInformation = string.Format("您输入的[{0}]不是数字!",num);
            Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - msg.Width, Screen.PrimaryScreen.WorkingArea.Height);
            msg.PointToClient(p);
            msg.Location = p;
            msg.Show();
            for (int i = 0; i < msg.Height; i++)
            {
                msg.Location = new Point(p.X, p.Y - i);
                System.Threading.Thread.Sleep(0);//消息框弹出速度,数值越大越慢
            }
        }

弹窗的主要事件

  [DllImport("user32")]
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);

  int AW_ACTIVE = 0x20000; //激活窗口,在使用了AW_HIDE标志后不要使用这个标志   
        int AW_HIDE = 0x10000;//隐藏窗口   
        int AW_BLEND = 0x80000;// 使用淡入淡出效果   
        int AW_SLIDE = 0x40000;//使用滑动类型动画效果,默认为滚动动画类型,当使用AW_CENTER标志时,这个标志就被忽略   
        int AW_CENTER = 0x0010;//若使用了AW_HIDE标志,则使窗口向内重叠;否则向外扩展   
        int AW_HOR_POSITIVE = 0x0001;//自左向右显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志   
        int AW_HOR_NEGATIVE = 0x0002;//自右向左显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志   
        int AW_VER_POSITIVE = 0x0004;//自顶向下显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志   
        int AW_VER_NEGATIVE = 0x0008;//自下向上显示窗口,该标志可以在滚动动画和滑动动画中使用。使用AW_CENTER标志时忽略该标志

        private int currentX;//横坐标      
        private int currentY;//纵坐标      
        private int screenHeight;//屏幕高度      
        private int screenWidth;//屏幕宽度 

        private void timerStart_Tick(object sender, EventArgs e)
        {
            if (this.Opacity > 0 && this.Opacity <= 1)//开始执行弹出窗渐渐透明  
            {
                this.Opacity = this.Opacity - 0.05;//透明频度0.05  
            }
            if (this.Opacity == 0)//当透明度==0的时候,关闭弹出窗以释放资源。  
            {
                this.Close();
            }
        }

 private void Message_Load(object sender, EventArgs e)
        {
            label1.Text = GetInformation; 
            Rectangle rect = Screen.PrimaryScreen.WorkingArea;
            screenHeight = rect.Height;
            screenWidth = rect.Width;
            currentX = screenWidth - this.Width;
            currentY = screenHeight - this.Height;
            this.Location = new System.Drawing.Point(currentX, currentY);
            AnimateWindow(this.Handle, 10, AW_SLIDE | AW_VER_NEGATIVE);
            //10用于弹窗弹出速度,值越大,速度越慢
        }

下载Demo连接:https://download.csdn.net/download/lipeng363622798/88963700

相关推荐

  1. C# 构建可定时关闭异步提示

    2024-03-20 16:48:03       21 阅读
  2. 【Vue】登录功能中对于错误提示信息重构

    2024-03-20 16:48:03       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-20 16:48:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-20 16:48:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-20 16:48:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-20 16:48:03       20 阅读

热门阅读

  1. UDP客户端与服务端执行bind和connect

    2024-03-20 16:48:03       19 阅读
  2. leetcode刷题笔记

    2024-03-20 16:48:03       24 阅读
  3. vue系列:使用vue3、ant-d,a-select下拉的搜索功能

    2024-03-20 16:48:03       18 阅读
  4. Python运算符、表达式、数据类型及常用关键字

    2024-03-20 16:48:03       14 阅读
  5. 条件随机场(CRF)笔记

    2024-03-20 16:48:03       20 阅读
  6. 王道机试指南 复试机试准备day1

    2024-03-20 16:48:03       19 阅读
  7. AI自动绘画生成器,AI自动绘画工具使用教程

    2024-03-20 16:48:03       29 阅读
  8. 国内外主流 TOF 相机品牌与参数

    2024-03-20 16:48:03       34 阅读
  9. 【Python 48小时速成 4】注释

    2024-03-20 16:48:03       19 阅读