首页 > 解决方案 > 如何将 ConsoleWrite 更改为标签文本

问题描述

好吧,我一直在使用我的 IP Get 和 console.write 函数,但是有一个问题,我不知道 Console.Write 做什么,我只需要该代码将转到标签文本,这意味着当 IP 获取时,它会转到Label.Text BTW,我使用Visual Studio c#。

private void metroLabel1_Click(object sender, EventArgs e)
    {
         String strHostName = string.Empty;
         // Getting Ip address of local machine...
         // First get the host name of local machine.
         strHostName = Dns.GetHostName();
         Console.WriteLine("Local Machine's Host Name: " + strHostName);
         // Then using host name, get the IP address list..
         IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
         IPAddress[] addr = ipEntry.AddressList;

         for (int i = 0; i < addr.Length; i++)
         {
             Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString());
            //metroLabel1.Text = " >> " + "", i, addr[i].ToString());
           // Console.WriteLine = metroLabel1.Text;

        }
         Console.ReadLine();



    }

标签: c#

解决方案


尝试这个

metroLabel1.Text = inputString

推荐阅读