请解决它我无法打印消息或警告meesage [英] Please resolve it I m unable to print the message or an alert meesage

查看:113
本文介绍了请解决它我无法打印消息或警告meesage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (Convert.ToInt32(Txtfrst.Text) > Convert.ToInt32(Txtsecnd.Text))
                Txtresult.Text = Convert.ToString(Convert.ToInt32(Txtfrst.Text) - Convert.ToInt32(Txtsecnd.Text));
            else
            {
                MessageBox.Show("please enter frstno greater than second number");
                alert("frst no shd be greatr than secnd");
            }





我的尝试:



i试图在消息框中打印消息或作为警告



What I have tried:

i tried to print message in message box or as an alert

推荐答案

MessageBox和alert不兼容:它们用于不同的环境。

MessageBox仅适用于Windows应用程序 - 如果您尝试在Web项目中使用它们,它们将无法工作。

警报仅适用于Web项目 - 它们可以不能在Windows项目中使用。

可能,你的问题是Convert.ToInt32是一个坏主意。如果您尝试转换的值不是有效整数,则会抛出异常 - 并且您的Windows应用程序(或线程)将崩溃,除非您抓住它,或者您的Web应用程序将失败并且可能没有响应。

尝试使用它们都是一种灾难,因为MessageBox是模态的,只有用户 - 无法看到它 - 点击按钮才会做任何事情。



而不是转换,总是使用TryParse,并正确报告问题:

"MessageBox" and "alert" are incompatible: they are used in different environments.
MessageBox is only applicable to Windows applications - if you try to use them in web projects, they will not work.
Alert is only applicable to web projects - they can't be used in Windows projects.
And probably, your problem is that Convert.ToInt32 is a bad idea. If the value you try to convert is not a valid integer, it throws an exception - and your Windows application (or thread) will crash unless you catch it, or your web application will fail and probably show no response.
Trying to use them both is a recipe for disaster, as MessageBox is modal and will do nothing until the user - who can't see it - clicks a button.

Instead of Convert, always use TryParse, and report problems properly:
int first;
if (!int.TryParse(txtfrst.Text, out first))
   {
   ... report problem to user ...
   return;
   }

然后,您可以在有效性测试中使用转换后的值,而不会有应用程序崩溃的风险。

找出您正在使用的系统,并查找适当的沟通方式!

You can then use converted values in your validity tests without risk of your app crashing.
And work out what system you are working on, and look for the appropriate communication method!


这篇关于请解决它我无法打印消息或警告meesage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆