//这段代码是获得网页中的图片,并付值给本类中的ImageList
do
{
ws = ws.Substring( ws.IndexOf( "a_70" ) + 8 );
wiString = ws.Substring( 0, 7 );
//图片放置的详细的地址
wiString = "http://www.nmc.gov.cn/img/weather/a_70x65/" + wiString;
imgStream = ScreenWeather.OpenRead( wiString );
wImage.Add(Image.FromStream( imgStream ));
i = i + 1;
}
while ( ws.IndexOf( "a_70" ) != -1 );
//这段代码是对页面HTML代码进行分析,提取相关的天气信息
ws = ws.Substring( ws.IndexOf( "气温" ) + 3 );
lapse = ws.Substring( 0, ws.IndexOf( "<" ) );
ws = ws.Substring( ws.IndexOf( "风向" ) + 5 );
wind = ws.Substring( 0, ws.IndexOf( "<" ) );
ws = ws.Substring( ws.IndexOf( "日期" ) + 4 );
date = ws.Substring( 0, ws.IndexOf( "<" ) );
}
}
//访问网页失败时显示默认的图片
public void GetLocal()
{
wImage.Clear();
//可以换成任意默认的图片
wImage.Add(Properties.Resources.na);
}
//绘图函数,完成天气的绘制
public void Paint ( PaintEventArgs e )
{
Point imgPoint = wPoint;
foreach ( Image img in wImage )
{
e.Graphics.DrawImage( img, imgPoint );
imgPoint.X = imgPoint.X + img.Width;
}
Rectangle detail=new Rectangle(wPoint.X,wPoint.Y+wImage[0].Height,wImage[0].Width*2,wImage[0].Height);
e.Graphics.DrawString( city + " " + date + " " + wind + "\n " + lapse + " " + weatherDetail, font, brush, detail );
}
//析构函数
public void Dispose()
{
if (brush != null)
brush.Dispose();
if (font != null)
font.Dispose();
}
|