به خاطر اینه که چنین آدرسی وجود نداره(در مرورگر وارد کنی همین پیغام رو میگیری.
با try ... catch کنترل کن:
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
Image img = null;
try
{
WebRequest req = WebRequest.Create("http://avatar.nimbuzz.com/getAvatar?jid=" + textBox1.Text + "@nimbuzz.com");
WebResponse res = req.GetResponse();
Stream stream = res.GetResponseStream();
img = Image.FromStream(stream);
}
catch (WebException wex)
{
if (wex.Message.Contains("(404)"))
{
img = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics g = Graphics.FromImage(img);
g.FillRectangle(Brushes.Black, 0, 0, img.Width, img.Height);
string messageStr = "عکس یافت نشد";
Font font = new Font("Tahoma", 14);
SizeF stringSize = g.MeasureString(messageStr, font);
int x = (int)(img.Width / 2 - stringSize.Width / 2);
int y = (int)(img.Height / 2 - stringSize.Height / 2);
Point stringLocation = new Point(x, y);
g.DrawString(messageStr, font, Brushes.White, stringLocation);
}
else
{
img = null;
}
}
finally
{
pictureBox1.Image = img;
}