0

hi all,
i want to write a c# code that display the picture of user's windows account in picturebox, so if any one know how do you call and display the user's picture in a picturebox using c#
I try the following code but nothing happened:

private void button1_Click(object sender, EventArgs e)
{
Image myimage = GetUserImage();
pictureBox1.Image = myimage;



}
private Image GetUserImage()
{
string TempPath = Environment.GetEnvironmentVariable("TEMP");
MessageBox.Show(TempPath);
string UserName = Environment.GetEnvironmentVariable("USERNAME");
MessageBox.Show(UserName);
string ImagePath = String.Format("{0}\\{1}.bmp", TempPath, UserName);
if (System.IO.File.Exists(ImagePath))
{
MessageBox.Show("there is an image");
return Image.FromFile(String.Format("{0}\\{1}.bmp", TempPath, UserName));


}
else
{
MessageBox.Show("null");
return null;


}
}

if any one has any idea, please tell me soon.
thank you very much

Edited by happygeek: fixed formatting

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by JerryShaw
0

Did you trace through the code with the debugger ?
Is there actually a bitmap file with the user's name in that directory ?

// Jerry

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.