Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
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..........

C#
private void button1_Click(object sender, EventArgs e)

{

string name = System.Environment.MachineName;

textBox1.Text = name[0].ToString();

}


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
Posted
Updated 28-Jan-13 6:12am
v2

Here goes:
private void button1_Click(object sender, EventArgs e)
{
 string name = System.Environment.MachineName;
 textBox1.Text = name.ToString(); 
}


Best regards
Espen Harlinn
 
Share this answer
 
Comments
Joezer BH 28-Jan-13 12:17pm    
5+

I see that the question was FAR simpler than I thought ...
Espen Harlinn 28-Jan-13 14:30pm    
Thank you, Edo :-D
Joezer BH 28-Jan-13 12:18pm    
As Espen here showed you, the name[0] only gets the first char of the string "name"
Sergey Alexandrovich Kryukov 28-Jan-13 12:47pm    
Yes, what else? A 5.
—SA
Espen Harlinn 28-Jan-13 14:30pm    
Thank you, Sergey :-D
This should fix your issue,
C#
TextBox1.Text = System.Environment.MachineName;
 
Share this answer
 
Comments
Espen Harlinn 28-Jan-13 14:32pm    
5'ed!
You need to remove the "[0]" from "name". That shows the first character.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900