检索用户计算机全名 [英] Retrieving User Computer Full Name
问题描述
我正在使用C#开发Windows应用程序。我有一个表单,其中我拖动了一个textBox和一个按钮控件。我想通过单击按钮在textBox中检索用户的完整计算机名。我为此写了一些代码..........
I am developing a Windows Application by using C#. I have a form in which I dragged one textBox and one button control. I want to retrieve the user Full Computer Name in the textBox by clicking the button.I wrote some codes for that as..........
private void button1_Click(object sender, EventArgs e)
{
string name = System.Environment.MachineName;
textBox1.Text = name[0].ToString();
}
单击按钮,它只检索第一个字母(例如:D表示Donald- PC)计算机名称的启动,但我想检索全名(例如:Donald-PC)。如果我在代码中做了任何更改,请有人帮忙。谢谢
By clicking the button, it retrieves only the first letter(eg: D for Donald-PC) of the Computer Name by which it starts but I want to retrieve the Full Name(eg: Donald-PC). Please someone help if I have make any change in my codes.Thanks
推荐答案
这里有:
Here goes:
private void button1_Click(object sender, EventArgs e)
{
string name = System.Environment.MachineName;
textBox1.Text = name.ToString();
}
最好的问候
Espen Harlinn
Best regards
Espen Harlinn
这应该可以解决你的问题,
This should fix your issue,
TextBox1.Text = System.Environment.MachineName;
您需要从名称中删除[0]。这显示了第一个字符。
You need to remove the "[0]" from "name". That shows the first character.
这篇关于检索用户计算机全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!