将成功ping通到消息框 [英] Ping success into messagebox

查看:118
本文介绍了将成功ping通到消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

您好创建了一个ping应用程序,我的问题是何时完成
我希望它在完成时以及
时显示一个消息框 它遇到错误,我希望它也显示另一个消息框.

这是代码.目前,它在输出中显示了
窗户.我也希望在消息框中

请任何帮助..

字符串IP;
....

Hi all,

Hi created a ping app, my problem is when it is finished
I want it to display a messagebox when it is finished and if
it run into an error I want it to also display another messagebox.

Here is the code. at the moment it shows it in the output
window. I want it in the messagebox aswell

Please any help would be appriciated..

string IP;
....

IP = txtIPAddr.Text;
            using (Ping ping = new Ping())
            {
                try
                {
                    Console.Write("    {0}...", IP);
                    PingReply reply = ping.Send(IP, 100);
                    if (reply.Status == IPStatus.Success)
                    {
                        Console.WriteLine("Success - IP Address:{0}", reply.Address, reply.RoundtripTime);
                    }
                    else
                    {
                        Console.WriteLine(reply.Status);
                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Error ({0})",
                        ex.InnerException.Message);
                }
            }

推荐答案

从外观上看,它是一个控制台应用程序-虽然您可以从控制台应用程序显示消息框,但这并不是真的一个好主意.

如果必须,则:
1)在项目中添加对System.Windows.Forms的引用.
2)添加以下行:
By the look of it, that is a console app - whiule you can display a message box from a Console app, it isn''t really a good idea.

If you must, then:
1) Add a Reference to System.Windows.Forms to your project.
2) Add the line:
using System.Windows.Forms;

到您的代码.
3)现在可以使用MessageBox.Show代替Console.WriteLine.

但是,改用WinForms应用程序要好得多.

To your code.
3) You can now use MessageBox.Show instead of Console.WriteLine.

But it is a much, much better idea to switch to a WinForms app instead.


这篇关于将成功ping通到消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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