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

  • 23
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值