从代码到标签 [英] From code to label

查看:96
本文介绍了从代码到标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让这个代码显示标签,来自互联网供应商的IP地址?


 公共字符串GetIPAddress()

        {

            IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); //'Dns.Resolve()`方法已被弃用。

            IPAddress ipAddress = ipHostInfo.AddressList [0];



            return ipAddress.ToString();

        }


解决方案

嗨GeyBen420,



你的意思是显示ipAddress到Label控件吗?


如果这是真的,那么得到一个标签控件从工具箱,


并将您的函数分配给标签控件的属性


如下所示,





        private void button1_Click(object sender,EventArgs e)

        {

            string text = GetIPAddress();
$


            label1.Text = text;

        }


祝你好运


E-John






How to make this code show to label, the ip address from the internet supplier?

  public string GetIPAddress()
        {
            IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); // `Dns.Resolve()` method is deprecated.
            IPAddress ipAddress = ipHostInfo.AddressList[0];

            return ipAddress.ToString();
        }

解决方案

Hi GeyBen420,

Do you mean to show the ipAddress to Label control?

If this is true, then get a label control from Toolbox,

and assign your function to property of label control

Like follows,


        private void button1_Click(object sender, EventArgs e)
        {
            string text = GetIPAddress();

            label1.Text = text;
        }

Best regards

E-John



这篇关于从代码到标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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