0
C#의 경우 약간의 문제가 있습니다.배경이 업데이트되지 않음 C#
사용자가 지정한 이미지를 다운로드하여 내 양식의 배경을 동적으로 업데이트하려고합니다. 왜 내 양식이 업데이트 된 배경을 표시하지 않습니다에 관한
public bool getImgFromWeb(string url)
{
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url, UriKind.Absolute));
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//if response is okay, and it's an image
//sometimes 404 will be okay, but will redirect to website.
if ((response.StatusCode == HttpStatusCode.OK) &&
(response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase)))
{
Bitmap tempImg = new Bitmap(response.GetResponseStream());
this.BackgroundImage = tempImg; //this line does nothing.
this.Invalidate(); //to force the window to redraw
}
else
{
MessageBox.Show("Sorry, the image your are trying to download does not exist. Please re-enter the image URL.");
return false;
}
}
catch (Exception ex)
{
MessageBox.Show("Sorry, an error: " + ex.Message + " occurred.");
return false;
}
제안 : (양식 및 업데이트) 이미지를 다운로드하려면 코드
은 다음과 같습니다?
감사합니다.
getImgFromWeb은 무엇을 호출합니까? 다른 메모에서는 GetImgFromWeb에 대한 메서드의 이름을 표준 C# 명명 규칙을 따르도록 변경해야합니다. –
실제 예외는 무엇입니까? – daryal
'this.Show();'를 코드에 추가하면 폼을 볼 수 있습니다. 잘못된 형식입니다. –