Click here to Skip to main content
12,079,391 members (26,550 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#2.0 C#
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();
 
}

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 28-Jan-13 7:10am
Edited 28-Jan-13 7:12am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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

Best regards
Espen Harlinn
  Permalink  
Comments
Edo Tzumer 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
Edo Tzumer 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

This should fix your issue,
TextBox1.Text = System.Environment.MachineName;
  Permalink  
Comments
Espen Harlinn 28-Jan-13 14:32pm
   
5'ed!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

You need to remove the "[0]" from "name". That shows the first character.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160212.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100