简体   繁体   English

显示图片框? 我看不到我在做什么错

[英]Displaying a picturebox? I don't see what I am doing wrong here

I am checking to see if a server was reachable, then setting a picturebox's "Visible" boolean to true. 我正在检查服务器是否可以访问,然后将图片框的“可见”布尔值设置为true。 However, when I first ran the code, no errors appeared, but no picturebox appeared either. 但是,当我第一次运行代码时,没有出现错误,但是也没有出现图片框。

There is a offlinePic (Sets Visible boolean to true, and brings to front when the test fails) There is a onlinePic (Sets Visible boolean to true, and brings to front when the test passes) 有一个offlinePic(将Visible布尔值设置为true,并在测试失败时显示在最前面)有一个onlinePic(将Visible布尔值设置为true,并在测试通过时显示在最前面)

I thought it would be possible that it was the server screwing things up, so I changed it to try with Google.com, and there is no difference. 我认为可能是服务器搞砸了,所以我将其更改为可以在Google.com上尝试,并且没有区别。

private void Launcher_Load(object sender, EventArgs e)
    {
        TestServerConnection();
    }
    public void TestServerConnection()
    {
        string url = "www.google.com";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Timeout = 15000;
        request.Method = "HEAD";
        try
        {
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                if (onlinePic.Visible == false) onlinePic.Visible = true;
                onlinePic.BringToFront();
            }
        }
        catch (WebException)
        {
            if (offlinePic.Visible == false) offlinePic.Visible = true;
            offlinePic.BringToFront();
        }
    }

The format for your url is wrong. 您的网址格式错误。
www.google.com should be http://www.google.com www.google.com应该是http://www.google.com

Everything else works fine for me. 其他一切对我来说都很好。

Not all servers can respond on HEAD try to use GET instead in request.Method . 并非所有服务器都可以在HEAD响应,而是尝试在request.Method使用GET And specify protocol http in the URL. 并在URL中指定协议http

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与XML名称空间(linq)纠缠...在这里我做错了什么? - struggling with XML namespaces (linq)… what am I doing wrong here? 泛型与继承:我在这里做错了什么? - Generics & Inheritance: What am I doing wrong here? 呼叫网络服务:我在这里做错了什么? - Calling a web service: what am I doing wrong here? 我在用IQueryable做错什么 <T> ? - What am I Doing Wrong with IQueryable<T>? 有时我不知道某些方法属于哪些类。 我究竟做错了什么? - Sometimes I don't know which classes certain methods belong to. What am I doing wrong? 这个小代码的ForEach替换不能达到我的预期。 我在这做错了什么? - The ForEach Replace on this small code doesn't do what I expected it to do. What am I doing wrong here? 我正在验证 C# 中的表格,但我不知道我做错了什么。 请帮我解决这个问题 - I'm validating a form in C# but I don't know what I am doing wrong. Please help me solve this C#错误-不包含接受1个参数的构造函数-我不明白我在做什么错? - C#-Error-does not contain a constructor that takes 1 arguments-I don't get what I am doing wrong? 收到错误,Collection 被修改; 枚举操作可能无法执行,但我不知道我做错了什么,在哪里? - Receiving an error, Collection was modified; enumeration operation may not execute, but I don't know what I am doing wrong and where? 我正在统一使用Raycast,当我单击它时我想获取对象的位置,但是我不工作并且我不知道我在做什么错 - I am using Raycast in unity and i want to get the position of an object when i click on it but i does not work and i don't know what i am doing wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM