for this source code ,it's free
all write by : wgscd
date Time :2008/11/24
contact :wgscd2126.com qq:153964481
bLOG :HTTP://BLOG.youkuaiyun.com/WGSNET
-------------------------------------------------------------
BigPicLoader.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;
using System.Web;
using System.IO;
namespace QQAlbum
{
public partial class BigPicLoader : UserControl
{
public BigPicLoader()
{
InitializeComponent();
}
public BigPicLoader(string PicURL)
{
InitializeComponent();
}
public BigPicLoader(string PicURL, object obj)
{
InitializeComponent();
}
System.Windows.Forms.Timer picTimer = new System.Windows.Forms.Timer();
public string PicUrl = "http://www.baidu.com/img/logo-yy.gif";
public string SavePath = "c://ok.gif";
public bool isLoadCompleted = false;
public static Size PicLoaderSize = new Size(300, 200);
Stream myStrem;
bool canLoadPic = false;
PicLoadState LoaderSate = PicLoadState.NotInit;
public bool zoomInFlag = true;// 放大表示
enum PicLoadState
{
NotInit = 1,
Begin = 2,
Loading = 3,
LoadCompleted = 4,
Err = 5
}
private void PicLoader_Load(object sender, EventArgs e)
{
picTimer.Tick += new EventHandler(picTimer_Tick);
LBloadingGIF.Visible = false;
}
private void pictureBox1_Resize(object sender, EventArgs e)
{
//this.Size=this.pictureBox1.Size;
//if(this.Parent !=null){
//this.Location = new Point((this.Parent.Width - this.Width) / 2, (this.Parent.Height - this.Height) / 2);
// }
}
public string LoadPic(string _PicUrl)
{
LoaderSate = PicLoadState.Begin;
PicUrl = _PicUrl;
// long t1 = DateTime.Now.Ticks;
int rand = new Random().Next(62);
if (rand < 10) { rand = 10; }
//PicUrl = @"http://www.ecounty.com.cn/Admin/PhotoList/uu8"+rand+".jpg";
//WebClient web = new WebClient();
// web.DownloadFileCompleted += new AsyncCompletedEventHandler(web_DownloadFileCompleted);
// web.DownloadProgressChanged += new DownloadProgressChangedEventHandler(web_DownloadProgressChanged);
try
{
//WebProxy proxy = new WebProxy("proxy.cd.ncsi.com.cn", 80);
//NetworkCredential crd = new NetworkCredential("guangshu", "Ncs1234");//, "ncs.corp.int-ads");
//proxy.Credentials = crd;
HttpWebRequest request = (HttpWebRequest)(HttpWebRequest.Create(PicUrl));
if (ModCommon.isProxy)
{
request.Proxy = ModCommon.getProxy();
}
myStrem = request.GetResponse().GetResponseStream();
pictureBox1.Image = Image.FromStream(myStrem);
LoaderSate = PicLoadState.LoadCompleted;
//StreamReader myReader = new StreamReader(myStrem, System.Text.Encoding.Default);
//FileStream Fstream = File.Open("c://" + rand + "1.jpg", FileMode.OpenOrCreate);
//StreamWriter myWriter = new StreamWriter(Fstream, System.Text.Encoding.Default);
//myWriter.Write(myReader.ReadToEnd());
//myWriter.Close();
//Fstream.Close();
//myReader.Close();
myStrem.Close();
}
catch (Exception ex)
{
pictureBox1.Image = pictureBox1.ErrorImage;
//LBloadingGIF.Visible = false;
LoaderSate = PicLoadState.Err;
//MessageBox.Show(ex.Message);
}
return "ok";
}
private void web_DownloadFileCompleted(object seder, AsyncCompletedEventArgs e)
{
pictureBox1.Image = Image.FromFile(SavePath);
pictureBox1.Size = pictureBox1.Image.Size;
MessageBox.Show("OK");
}
private void web_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
MessageBox.Show("DownloadProgressChanged");
}
public void doLoadPic(string _Url)
{
picTimer.Start();
PicUrl = _Url;
LoaderSate = PicLoadState.Begin;
LBloadingGIF.Visible = true;
picTimer.Start();
Thread thd_LoadPicture = new Thread(new ThreadStart(LoadPicture));
thd_LoadPicture.Start();
}
void LoadPicture()
{
LoadPic(PicUrl);
}
private void resizePic()
{
this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
this.Size = pictureBox1.Image.Size;
this.Location = new Point();
this.Location = new Point((this.Parent.Width - this.Width) / 2, (this.Parent.Height - this.Height) / 2);
}
private void picTimer_Tick(object sender, EventArgs e)
{
if (LoaderSate == PicLoadState.LoadCompleted || LoaderSate == PicLoadState.Err)
{
LBloadingGIF.Visible = false;
if (LoaderSate == PicLoadState.LoadCompleted)
{
resizePic();
}
picTimer.Stop();
return;
}
else
{
LBloadingGIF.Visible = true;
}
}
private void BigPicLoader_Resize(object sender, EventArgs e)
{
LBloadingGIF.Location = new Point((this.Width - LBloadingGIF.Width) / 2, (this.Height - LBloadingGIF.Height) /
2);
}
private void pictureBox1_Resize()
{
}
private void ZoomBigPicloader()
{
//int w = this.Width;
// int h = this.Height;
if (zoomInFlag)
{
while (this.Width >= (this.pictureBox1.Image.Width / 2))
{
this.Size = this.Size - (new Size(this.Size.Width / 30, this.Size.Height / 30));
Application.DoEvents();
this.Location = new Point((this.Parent.Width - this.Width) / 2, (this.Parent.Height - this.Height) /
2);
}
zoomInFlag = false;
//return;
}
else
{
while (this.Width < this.pictureBox1.Image.Width)
{
this.Size = this.Size + (new Size(this.Size.Width / 28, this.Size.Height / 28));
Application.DoEvents();
this.Location = new Point((this.Parent.Width - this.Width) / 2, (this.Parent.Height - this.Height) /
2);
}
zoomInFlag = true;
// return;
}
}
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
ZoomBigPicloader();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void savePictureToolStripMenuItem_Click(object sender, EventArgs e)
{
if (pictureBox1.Image != pictureBox1.ErrorImage)
{
SaveFileDialog sfd = new SaveFileDialog();
//ofd.Filter = "图片文件";
sfd.Filter = "图片文件|*.jpg;*.gif;*.png;*.tif";
if (sfd.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image.Save(sfd.FileName);
}
}
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
savePictureToolStripMenuItem.Enabled = !(bool)(pictureBox1.Image.Equals(pictureBox1.ErrorImage));
}
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
if (LoaderSate == PicLoadState.Err) { return; }
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
if (IsInLbZoom) { return; }
}
bool IsInLbZoom = true;
private void LbZoom_MouseEnter(object sender, EventArgs e)
{
IsInLbZoom = true;
}
private void LbZoom_MouseLeave(object sender, EventArgs e)
{
IsInLbZoom = false;
}
private void LbZoom_Click(object sender, EventArgs e)
{
ZoomBigPicloader();
}
//private void button1_Click(object sender, EventArgs e)
//{
// pictureBox1.Image.Save("C://333.jpg");
//}
}
}
-------------------------------------------------------------------
BigPicLoader.Designer.cs
namespace QQAlbum
{
partial class BigPicLoader
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.LBright = new System.Windows.Forms.Label();
this.LBbottom = new System.Windows.Forms.Label();
this.LBtop = new System.Windows.Forms.Label();
this.LBleft = new System.Windows.Forms.Label();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.savePictureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LBloadingGIF = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// LBright
//
this.LBright.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.LBright.Dock = System.Windows.Forms.DockStyle.Right;
this.LBright.Location = new System.Drawing.Point(504, 0);
this.LBright.Name = "LBright";
this.LBright.Size = new System.Drawing.Size(5, 401);
this.LBright.TabIndex = 1;
this.LBright.Text = "label1";
//
// LBbottom
//
this.LBbottom.BackColor = System.Drawing.SystemColors.ControlDark;
this.LBbottom.Dock = System.Windows.Forms.DockStyle.Bottom;
this.LBbottom.Location = new System.Drawing.Point(0, 396);
this.LBbottom.Name = "LBbottom";
this.LBbottom.Size = new System.Drawing.Size(504, 5);
this.LBbottom.TabIndex = 2;
//
// LBtop
//
this.LBtop.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.LBtop.Dock = System.Windows.Forms.DockStyle.Top;
this.LBtop.Location = new System.Drawing.Point(0, 0);
this.LBtop.Name = "LBtop";
this.LBtop.Size = new System.Drawing.Size(504, 5);
this.LBtop.TabIndex = 3;
//
// LBleft
//
this.LBleft.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.LBleft.Dock = System.Windows.Forms.DockStyle.Left;
this.LBleft.Location = new System.Drawing.Point(0, 5);
this.LBleft.Name = "LBleft";
this.LBleft.Size = new System.Drawing.Size(5, 391);
this.LBleft.TabIndex = 5;
//
// contextMenuStrip1
//
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
//
// savePictureToolStripMenuItem
//
this.savePictureToolStripMenuItem.Name = "savePictureToolStripMenuItem";
this.savePictureToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
//
// LBloadingGIF
//
this.LBloadingGIF.BackColor = System.Drawing.Color.Transparent;
this.LBloadingGIF.Image = global::QQAlbum.Properties.Resources.Loading2;
this.LBloadingGIF.Location = new System.Drawing.Point(158, 194);
this.LBloadingGIF.Name = "LBloadingGIF";
this.LBloadingGIF.Size = new System.Drawing.Size(132, 9);
this.LBloadingGIF.TabIndex = 4;
this.LBloadingGIF.Visible = false;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))),
((int)(((byte)(64)))));
this.pictureBox1.ContextMenuStrip = this.contextMenuStrip1;
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.ErrorImage = global::QQAlbum.Properties.Resources.err;
this.pictureBox1.Image = global::QQAlbum.Properties.Resources.err;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(509, 401);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_DoubleClick);
this.pictureBox1.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave);
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
this.pictureBox1.Resize += new System.EventHandler(this.pictureBox1_Resize);
this.pictureBox1.MouseEnter += new System.EventHandler(this.pictureBox1_MouseEnter);
//
// BigPicLoader
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.LBleft);
this.Controls.Add(this.LBtop);
this.Controls.Add(this.LBbottom);
this.Controls.Add(this.LBright);
this.Controls.Add(this.LBloadingGIF);
this.Controls.Add(this.pictureBox1);
this.Name = "BigPicLoader";
this.Size = new System.Drawing.Size(509, 401);
this.Load += new System.EventHandler(this.PicLoader_Load);
this.Resize += new System.EventHandler(this.BigPicLoader_Resize);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label LBright;
private System.Windows.Forms.Label LBbottom;
public System.Windows.Forms.PictureBox pictureBox1; //设置为public使外部可见
private System.Windows.Forms.Label LBloadingGIF;
private System.Windows.Forms.Label LBtop;
private System.Windows.Forms.Label LBleft;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem savePictureToolStripMenuItem;
}
}
---------------------------------------------------------------
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Xml;
using System.Collections;
using System.Threading;
namespace QQAlbum
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ArrayList PicList = new ArrayList();
ModCommon mod = new ModCommon();
private void Form1_Load(object sender, EventArgs e)
{
//testXML();
}
void testXML()
{
XmlDocument doc = new XmlDocument();
doc.Load("C://5.xml");
XmlNodeList list = doc.SelectNodes("album/pic");
ModCommon.PicItem picItem;
PicList.Clear();
foreach (XmlNode nod in list)
{
picItem = new ModCommon.PicItem("", nod.ChildNodes[0].InnerText, nod.ChildNodes[1].InnerText, "",
nod.ChildNodes[2].InnerText, nod.ChildNodes[3].InnerText);
PicList.Add(picItem);
// nod.ChildNodes[2].InnerText;
MessageBox.Show(nod.ChildNodes[2].InnerText);
//Picinfo pi = new Picinfo();
//pi.BigPicURL = nod.ChildNodes[2].InnerText;
//pi.thumbURL = nod.ChildNodes[9].ChildNodes[0].InnerText;
//pi.Title = nod.ChildNodes[0].InnerText;
//piList.Add(pi);
//MessageBox.Show(nod.ChildNodes[2].InnerText);
//MessageBox.Show(nod.ChildNodes[9].ChildNodes[0].InnerText);
}
ModCommon.PicItem[] pics;
pics = new ModCommon.PicItem[PicList.Count];
for (int i = 0; i < PicList.Count; i++)
{
pics[i] = (ModCommon.PicItem)PicList[i];
}
CreatePicLoaders(pics);
}
private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (((int)(e.KeyChar)) == 13 && textBox1.Text.Trim() != "")
{
//MessageBox.Show("do");
//do .......
return;
}
this.Text = ((int)e.KeyChar).ToString();
if (!(Char.IsNumber(e.KeyChar)))
{
if (((int)(e.KeyChar)) == 8)
{
e.Handled = false;
return;
}
e.Handled = true;
}
}
private void BtnGet_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
PicList.Clear();
flowLayoutPanel1.Controls.Clear();
getQQAlbum();
}
void getQQAlbum()
{
LoadXML();
}
#region "创建缩略图"
delegate void myDelegate(string[] _str);
void CreatePicLoaders(ModCommon.PicItem[] _Urls)
{
for (int i = 0; i < _Urls.Length; i++)
{
PicLoader myPicLoader = new PicLoader();
myPicLoader.Name = "PicLoader" + i.ToString();
myPicLoader.Size = new Size(120, 80);
myPicLoader.Tag = _Urls[i].burl;
myPicLoader.pictureBox1.Click += new EventHandler(myPicLoader_Click);
myPicLoader.Click += new EventHandler(myPicLoader_Click);
myPicLoader.doLoadPic(_Urls[i].surl);
flowLayoutPanel1.Controls.Add(myPicLoader);
}
//******************************************
}
#endregion
BigPicLoader Bp = null;
void myPicLoader_Click(object sender, EventArgs e) {
PicLoader pl;
//MessageBox.Show(sender.GetType().ToString());
//return;
if (sender.GetType().ToString() == "QQAlbum.PicLoader")
{
pl = (PicLoader)sender;
}
else {
pl = (PicLoader)(((PictureBox)(sender)).Parent);
}
//pl.doLoadPic(pl.Tag.ToString());
// pl.Size = new Size(333,333);
if(!flowLayoutPanel1.Controls.Contains(Bp)){
Bp = new BigPicLoader(pl.Tag.ToString());
Bp.Size = new Size(222,222);
}
Bp.doLoadPic(pl.Tag.ToString());
flowLayoutPanel1.Controls.Add(Bp);
flowLayoutPanel1.ScrollControlIntoView(Bp);
}
#region "LoadXML"
//http://p4.photo.qq.com/153964481/16
//http://photo.store.qq.com/http_staload.cgi?153964481/38201906
void LoadXML()
{
//MyLoadXmlState = LoadXmlState.Begin;
int rand = new Random().Next(22);
string PicUrl = @"http://p4.photo.qq.com/" + textBox1.Text + "/16";
XmlDocument doc = new XmlDocument();
try
{
HttpWebRequest request = (HttpWebRequest)(HttpWebRequest.Create(PicUrl));
if (ModCommon.isProxy)
{
request.Proxy = ModCommon.getProxy();
}
Stream myStrem = request.GetResponse().GetResponseStream();
StreamReader myReader = new StreamReader(myStrem, System.Text.Encoding.Default);
doc.LoadXml(myReader.ReadToEnd());
//doc.Save("C://xml.xml");
//MessageBox.Show(doc.SelectSingleNode("ResultSet").Attributes.Count.ToString());
XmlElement l = doc.DocumentElement;
XmlNode ownername = doc.SelectSingleNode("data/left/album/ownername"); // owner name
//MessageBox.Show(ownername.InnerText);
XmlNode picnum = doc.SelectSingleNode("data/left/album/picnum"); //pic number
XmlNode albumnum = doc.SelectSingleNode("data/left/album/albumnum"); //album number
string AlbumInfo = ownername.InnerText + "专辑数:" + albumnum.InnerText + "-图片数" + picnum.InnerText;
this.Text = AlbumInfo;
XmlNodeList list = doc.SelectNodes("data/album");
ModCommon.AlbumItem albumItem;
foreach (XmlNode nod in list)
{
albumItem = new ModCommon.AlbumItem(nod.ChildNodes[0].InnerText, nod.ChildNodes[1].InnerText,
nod.ChildNodes[4].InnerText, nod.ChildNodes[5].InnerText, nod.ChildNodes[2].InnerText);
listBox1.Items.Add(albumItem);
//Picinfo pi = new Picinfo();
//pi.BigPicURL = nod.ChildNodes[2].InnerText;
//pi.thumbURL = nod.ChildNodes[9].ChildNodes[0].InnerText;
//pi.Title = nod.ChildNodes[0].InnerText;
//piList.Add(pi);
//MessageBox.Show(nod.ChildNodes[2].InnerText);
//MessageBox.Show(nod.ChildNodes[9].ChildNodes[0].InnerText);
}
//myReader.Close();
myStrem.Close();
//this.Text = ((DateTime.Now.Ticks - t1) / 10000).ToString();
//MyLoadXmlState = LoadXmlState.LoadCompleted;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//MyLoadXmlState = LoadXmlState.Err;
}
}
#endregion
void loadXmlAlbumItem(string _url)
{
//MyLoadXmlState = LoadXmlState.Begin;
XmlDocument doc = new XmlDocument();
try
{
HttpWebRequest request = (HttpWebRequest)(HttpWebRequest.Create(_url));
if (ModCommon.isProxy)
{
request.Proxy = ModCommon.getProxy();
}
Stream myStrem = request.GetResponse().GetResponseStream();
StreamReader myReader = new StreamReader(myStrem, System.Text.Encoding.Default);
doc.LoadXml(myReader.ReadToEnd());
//MessageBox.Show(myReader.ReadToEnd());
// return;
XmlNodeList list = doc.SelectNodes("album/pic");
ModCommon.PicItem picItem;
PicList.Clear();
foreach (XmlNode nod in list)
{
picItem = new ModCommon.PicItem("", nod.ChildNodes[0].InnerText, nod.ChildNodes[1].InnerText, "",
nod.ChildNodes[2].InnerText, nod.ChildNodes[3].InnerText);
PicList.Add(picItem);
// nod.ChildNodes[2].InnerText;
// MessageBox.Show(nod.ChildNodes[2].InnerText);
//Picinfo pi = new Picinfo();
//pi.BigPicURL = nod.ChildNodes[2].InnerText;
//pi.thumbURL = nod.ChildNodes[9].ChildNodes[0].InnerText;
//pi.Title = nod.ChildNodes[0].InnerText;
//piList.Add(pi);
//MessageBox.Show(nod.ChildNodes[2].InnerText);
//MessageBox.Show(nod.ChildNodes[9].ChildNodes[0].InnerText);
}
myReader.Close();
myStrem.Close();
//this.Text = ((DateTime.Now.Ticks - t1) / 10000).ToString();
//MyLoadXmlState = LoadXmlState.LoadCompleted;
ModCommon.PicItem[] pics;
pics = new ModCommon.PicItem[PicList.Count];
for (int i = 0; i < PicList.Count; i++)
{
pics[i] = (ModCommon.PicItem)PicList[i];
}
CreatePicLoaders(pics);
}
catch (Exception ex)
{
// MessageBox.Show("相册不能浏览,可能有密码限制!");
//MyLoadXmlState = LoadXmlState.Err;
}
}
string AlbumDetailUrl;
//http://photo.store.qq.com/http_staload.cgi?153964481/38201906
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedIndices.Count <= 0)
{
return;
}
AlbumDetailUrl = "http://photo.store.qq.com/http_staload.cgi?" + textBox1.Text.Trim() + "/" +
((ModCommon.AlbumItem)listBox1.SelectedItem).ID.Trim();
loadXmlAlbumItem(AlbumDetailUrl);
MessageBox.Show(AlbumDetailUrl);
// textBox2.Text = AlbumDetailUrl;
// Thread th = new Thread(new ThreadStart(getPics));
// th.Start();
}
void getPics()
{
loadXmlAlbumItem(AlbumDetailUrl);
}
private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
---------------------------------------------------------------
Form1.Designer.cs
namespace QQAlbum
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.paneltop = new System.Windows.Forms.Panel();
this.BtnGet = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.panelleft = new System.Windows.Forms.Panel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel1 = new System.Windows.Forms.Panel();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.label1 = new System.Windows.Forms.Label();
this.bigPicLoader1 = new QQAlbum.BigPicLoader();
this.paneltop.SuspendLayout();
this.panelleft.SuspendLayout();
this.panel1.SuspendLayout();
this.flowLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// paneltop
//
this.paneltop.BackColor = System.Drawing.SystemColors.ButtonFace;
this.paneltop.Controls.Add(this.label1);
this.paneltop.Controls.Add(this.BtnGet);
this.paneltop.Controls.Add(this.textBox1);
this.paneltop.Dock = System.Windows.Forms.DockStyle.Top;
this.paneltop.Location = new System.Drawing.Point(0, 0);
this.paneltop.Name = "paneltop";
this.paneltop.Size = new System.Drawing.Size(859, 37);
this.paneltop.TabIndex = 0;
//
// BtnGet
//
this.BtnGet.Location = new System.Drawing.Point(158, 8);
this.BtnGet.Name = "BtnGet";
this.BtnGet.Size = new System.Drawing.Size(66, 23);
this.BtnGet.TabIndex = 1;
this.BtnGet.Text = "Get";
this.BtnGet.UseVisualStyleBackColor = true;
this.BtnGet.Click += new System.EventHandler(this.BtnGet_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(9, 9);
this.textBox1.Margin = new System.Windows.Forms.Padding(0);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(140, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "153964481";
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
//
// listBox1
//
this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox1.FormattingEnabled = true;
this.listBox1.HorizontalScrollbar = true;
this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.Margin = new System.Windows.Forms.Padding(12, 3, 3, 3);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(224, 446);
this.listBox1.TabIndex = 0;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// panelleft
//
this.panelleft.Controls.Add(this.listBox1);
this.panelleft.Dock = System.Windows.Forms.DockStyle.Left;
this.panelleft.Location = new System.Drawing.Point(0, 37);
this.panelleft.Name = "panelleft";
this.panelleft.Size = new System.Drawing.Size(224, 456);
this.panelleft.TabIndex = 1;
//
// splitter1
//
this.splitter1.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.splitter1.Location = new System.Drawing.Point(224, 37);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(6, 456);
this.splitter1.TabIndex = 2;
this.splitter1.TabStop = false;
//
// panel1
//
this.panel1.Controls.Add(this.flowLayoutPanel1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(230, 37);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(629, 456);
this.panel1.TabIndex = 3;
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.AutoSize = true;
this.flowLayoutPanel1.Controls.Add(this.bigPicLoader1);
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(629, 456);
this.flowLayoutPanel1.TabIndex = 0;
this.flowLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.flowLayoutPanel1_Paint);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(230, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(394, 13);
this.label1.TabIndex = 2;
this.label1.Text = "输入QQ号码就可查看QQ相册 By wgscd QQ:153964481 mail:wgscd@126.com";
//
// bigPicLoader1
//
this.bigPicLoader1.Location = new System.Drawing.Point(3, 3);
this.bigPicLoader1.Name = "bigPicLoader1";
this.bigPicLoader1.Size = new System.Drawing.Size(369, 301);
this.bigPicLoader1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(859, 493);
this.Controls.Add(this.panel1);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.panelleft);
this.Controls.Add(this.paneltop);
this.Name = "Form1";
this.Text = "QQAlbum";
this.Load += new System.EventHandler(this.Form1_Load);
this.paneltop.ResumeLayout(false);
this.paneltop.PerformLayout();
this.panelleft.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.flowLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel paneltop;
private System.Windows.Forms.Button BtnGet;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Panel panelleft;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private BigPicLoader bigPicLoader1;
private System.Windows.Forms.Label label1;
}
}
---------------------------------------------------------------
PicLoader.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Threading;
using System.Web;
using System.IO;
using System.Net.Sockets;
using System.Drawing.Imaging;
namespace QQAlbum
{
public partial class PicLoader : UserControl
{
public PicLoader()
{
InitializeComponent();
}
public PicLoader(string PicURL)
{
InitializeComponent();
}
public PicLoader(string PicURL, object obj)
{
InitializeComponent();
}
public PicLoader(string PicURL, Size PSize)
{
this.Size = PSize;
InitializeComponent();
}
System.Windows.Forms.Timer picTimer = new System.Windows.Forms.Timer();
public string PicUrl = "http://www.baidu.com/img/logo-yy.gif";
public string SavePath = "c://ok.gif";
public bool isLoadCompleted = false;
public Size PicLoaderSize;
Stream myStrem;
bool canLoadPic = false;
PicLoadState LoaderSate = PicLoadState.NotInit;
Color thumbPicLoaderActivColor = Color.WhiteSmoke;
Color thumbPicLoaderNormColor = Color.Gray;
public string ErrMSG = "";
enum PicLoadState
{
NotInit = 1,
Begin = 2,
Loading = 3,
LoadCompleted = 4,
Err = 5
}
private void PicLoader_Load(object sender, EventArgs e)
{
picTimer.Tick += new EventHandler(picTimer_Tick);
PicLoaderSize = this.Size;
LBloadingGIF.Location = new Point((this.Width - LBloadingGIF.Width) / 2, (this.Height - LBloadingGIF.Height) /
2);
pictureBox1.Location = new Point((this.Width - pictureBox1.Width) / 2, (this.Height - pictureBox1.Height) / 2);
}
public string LoadPic(string _PicUrl)
{
// long t1 = DateTime.Now.Ticks;
int rand = new Random().Next(62);
if (rand < 10) { rand = 10; }
//PicUrl = @"http://www.ecounty.com.cn/Admin/PhotoList/uu8"+rand+".jpg";
//WebClient web = new WebClient();
// web.DownloadFileCompleted += new AsyncCompletedEventHandler(web_DownloadFileCompleted);
// web.DownloadProgressChanged += new DownloadProgressChangedEventHandler(web_DownloadProgressChanged);
LoaderSate = PicLoadState.Begin;
try
{
//WebProxy proxy = new WebProxy("proxy.fff.com.cn", 80);//set the proxy server
// NetworkCredential crd = new NetworkCredential("wgscd", "1234");//, "ncs.corp.int-ads");///the user and password for the proxy
// proxy.Credentials = crd;
HttpWebRequest request = (HttpWebRequest)(HttpWebRequest.Create(PicUrl));
if (ModCommon.isProxy)
{
request.Proxy = ModCommon.getProxy();
}
myStrem = request.GetResponse().GetResponseStream();
pictureBox1.Image = Image.FromStream(myStrem);
//pictureBox1_Resize();
// MessageBox.Show(pictureBox1.Image.Width.ToString() + "-" + pictureBox1.Image.Height.ToString());
//StreamReader myReader = new StreamReader(myStrem, System.Text.Encoding.Default);
//FileStream Fstream = File.Open("c://" + rand + "1.jpg", FileMode.OpenOrCreate);
//StreamWriter myWriter = new StreamWriter(Fstream, System.Text.Encoding.Default);
richTextBox1.Text = myReader.ReadToEnd();
//myWriter.Write(myReader.ReadToEnd());
//myWriter.Close();
//Fstream.Close();
//myReader.Close();
myStrem.Close();
LoaderSate = PicLoadState.LoadCompleted;
ErrMSG = "";//clear the Err Message
}
catch (Exception ex)
{
pictureBox1.Image = pictureBox1.ErrorImage;
LoaderSate = PicLoadState.Err;
//LBloadingGIF.Visible = false;
//MessageBox.Show(ex.Message);
ErrMSG = ex.Message;
}
return "ok";
}
private void web_DownloadFileCompleted(object seder, AsyncCompletedEventArgs e)
{
//pictureBox1.Image = Image.FromFile(SavePath);
//pictureBox1.Size = pictureBox1.Image.Size;
//MessageBox.Show("OK");
}
private void web_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
// MessageBox.Show("DownloadProgressChanged");
}
public void doLoadPic(string _url)
{
PicUrl = _url;
LoaderSate = PicLoadState.Begin;
LBloadingGIF.Visible = true;
this.Refresh();
picTimer.Start();
Thread thd_LoadPicture = new Thread(new ThreadStart(LoadPicture));
thd_LoadPicture.Start();
}
void LoadPicture()
{
LoadPic(PicUrl);
}
private void picTimer_Tick(object sender, EventArgs e)
{
if ((LoaderSate == PicLoadState.LoadCompleted) || (LoaderSate == PicLoadState.Err))
{
if (pictureBox1.Image != Properties.Resources.err)
{
//SavePicToFile(pictureBox1.Image);
}
LBloadingGIF.Visible = false;
reSizePic();
picTimer.Stop();
return;
}
}
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
LBright.BackColor = thumbPicLoaderActivColor;
LBleft.BackColor = thumbPicLoaderActivColor;
LBtop.BackColor = thumbPicLoaderActivColor;
LBbottom.BackColor = thumbPicLoaderActivColor;
// this.Size = this.Size + (new Size(this.Size.Width / 10, this.Size.Height/10));
//this.Top = this.Top - 3;
// this.Top = this.Left + 3;
// MessageBox.Show(PointToScreen(this.Location).ToString());
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
LBright.BackColor = thumbPicLoaderNormColor;
LBleft.BackColor = thumbPicLoaderNormColor;
LBtop.BackColor = thumbPicLoaderNormColor;
LBbottom.BackColor = thumbPicLoaderNormColor;
this.Size = PicLoaderSize;
//this.Top = this.Top + 3;
//this.Top = this.Left -3;
// this.Parent.Parent.Refresh();
}
void SavePicToFile(Image img)
{
try
{
if (Directory.Exists(ModCommon.SavePicFoder) == false) { return; }
ModCommon.PicCount = Directory.GetFiles(ModCommon.SavePicFoder).Length;
string strPath = ModCommon.SavePicFoder + "//" + ModCommon.PicCount.ToString("0000000");
img.Save(strPath + ".jpg", ImageFormat.Jpeg);
}
catch (Exception ex)
{
ErrMSG = ex.Message;
}
}
void reSizePic()
{
double w, h;
w = Convert.ToDouble(pictureBox1.Image.Width);
h = Convert.ToDouble(pictureBox1.Image.Height);
//this.Text = (w / h).ToString() + "--" + (Convert.ToDouble(pictureBox1.Width) / Convert.ToDouble
(pictureBox1.Height)).ToString();
if ((w / h) >= (Convert.ToDouble(pictureBox1.Parent.Width) / Convert.ToDouble(pictureBox1.Parent.Height)))
{
pictureBox1.Width = pictureBox1.Parent.Width - 8;
pictureBox1.Height = (int)(h * Convert.ToDouble(pictureBox1.Parent.Width) / w);
}
else
{
pictureBox1.Height = pictureBox1.Parent.Height - 8;
pictureBox1.Width = (int)(w * Convert.ToDouble(pictureBox1.Parent.Height) / h);
}
pictureBox1.Location = new Point((pictureBox1.Parent.Width - pictureBox1.Width) / 2, (pictureBox1.Parent.Height
- pictureBox1.Height) / 2);
}
}
}
---------------------------------------------------------------
PicLoader.Designer.cs
namespace QQAlbum
{
partial class PicLoader
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.LBright = new System.Windows.Forms.Label();
this.LBbottom = new System.Windows.Forms.Label();
this.LBloadingGIF = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.LBtop = new System.Windows.Forms.Label();
this.LBleft = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// LBright
//
this.LBright.BackColor = System.Drawing.Color.Gray;
this.LBright.Dock = System.Windows.Forms.DockStyle.Right;
this.LBright.Location = new System.Drawing.Point(392, 0);
this.LBright.Name = "LBright";
this.LBright.Size = new System.Drawing.Size(5, 332);
this.LBright.TabIndex = 1;
this.LBright.Text = "label1";
//
// LBbottom
//
this.LBbottom.BackColor = System.Drawing.Color.Gray;
this.LBbottom.Dock = System.Windows.Forms.DockStyle.Bottom;
this.LBbottom.Location = new System.Drawing.Point(0, 327);
this.LBbottom.Name = "LBbottom";
this.LBbottom.Size = new System.Drawing.Size(392, 5);
this.LBbottom.TabIndex = 2;
//
// LBloadingGIF
//
this.LBloadingGIF.BackColor = System.Drawing.Color.Transparent;
this.LBloadingGIF.Image = global::QQAlbum.Properties.Resources.Loading1;
this.LBloadingGIF.Location = new System.Drawing.Point(175, 151);
this.LBloadingGIF.Name = "LBloadingGIF";
this.LBloadingGIF.Size = new System.Drawing.Size(34, 28);
this.LBloadingGIF.TabIndex = 4;
this.LBloadingGIF.Visible = false;
//
// pictureBox1
//
this.pictureBox1.ErrorImage = global::QQAlbum.Properties.Resources.err;
this.pictureBox1.Image = global::QQAlbum.Properties.Resources.err;
this.pictureBox1.Location = new System.Drawing.Point(46, 28);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(324, 277);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave);
this.pictureBox1.MouseEnter += new System.EventHandler(this.pictureBox1_MouseEnter);
//
// LBtop
//
this.LBtop.BackColor = System.Drawing.Color.Gray;
this.LBtop.Dock = System.Windows.Forms.DockStyle.Top;
this.LBtop.Location = new System.Drawing.Point(0, 0);
this.LBtop.Name = "LBtop";
this.LBtop.Size = new System.Drawing.Size(392, 5);
this.LBtop.TabIndex = 3;
//
// LBleft
//
this.LBleft.BackColor = System.Drawing.Color.Gray;
this.LBleft.Dock = System.Windows.Forms.DockStyle.Left;
this.LBleft.Location = new System.Drawing.Point(0, 5);
this.LBleft.Name = "LBleft";
this.LBleft.Size = new System.Drawing.Size(5, 322);
this.LBleft.TabIndex = 5;
//
// PicLoader
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.LBleft);
this.Controls.Add(this.LBtop);
this.Controls.Add(this.LBbottom);
this.Controls.Add(this.LBright);
this.Controls.Add(this.LBloadingGIF);
this.Controls.Add(this.pictureBox1);
this.Name = "PicLoader";
this.Size = new System.Drawing.Size(397, 332);
this.Load += new System.EventHandler(this.PicLoader_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label LBright;
private System.Windows.Forms.Label LBbottom;
public System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label LBloadingGIF;
private System.Windows.Forms.Label LBtop;
private System.Windows.Forms.Label LBleft;
}
}
---------------------------------------------------------------
ModCommon.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Net;
using System.Web;
using System.IO;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace QQAlbum
{
class ModCommon
{
//申明INI文件的写操作函数WritePrivateProfileString()
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
//申明INI文件的读操作函数GetPrivateProfileString()
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int
size, string filePath);
// WritePrivateProfileString(FileName,key1,keyValue1,path) ;
//GetPrivateProfileString ("FiatDataBase" ,"UserId" , "" , temp3 , 255 , s1 ) ;
//写INI文件
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, ConfigIinFile);
}
//读取INI文件指定
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, ConfigIinFile);
return temp.ToString();
}
public static int listBox1SelectIndex = 0;
public static int listBox2SelectIndex = 0;
public static int listBox3SelectIndex = 0;
public static int comBox1SelectIndex = 0;
public static bool isProxy = true;
public static int PicCount = 2;
public static string SavePicFoder = "MM";
public static string ConfigIinFile = "Config.ini";
public string getHttpPage(string _url)
{
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(_url);
if (isProxy)
{
myRequest.Proxy = getProxy();
}
try
{
Stream myStrem = myRequest.GetResponse().GetResponseStream();
StreamReader myReader = new StreamReader(myStrem, Encoding.Default);
string strReturn = myReader.ReadToEnd();
myReader.Close();
myStrem.Close();
return strReturn;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return "Err";
}
}
public static WebProxy getProxy()
{
WebProxy proxy = new WebProxy("proxy.cd.ncsi.com.cn", 8080);
NetworkCredential cret = new NetworkCredential("guangshu", "Wgs1234", "Ncs");
proxy.Credentials = cret;
return proxy;
}
public class AlbumItem {
public AlbumItem(string _ID ,string _name, string _desc, string _total,string _surl)
{
ID = _ID;
name = _name;
desc = _desc;
total = _total;
surl = _surl;
}
public override string ToString()
{
return name;
}
public string ID = "";
public string name = "wgscd";
public string desc = "";
public string total = "";
public string surl = "";
}
public class PicItem
{
public PicItem(string _ID, string _name, string _desc, string _total, string _surl,string _burl)
{
ID = _ID;
name = _name;
desc = _desc;
total = _total;
surl = _surl;
burl = _burl;
}
public override string ToString()
{
return surl;
}
public string ID = "";
public string name = "wgscd";
public string desc = "";
public string total = "";
public string surl = "";
public string burl = "";
}
}
}
---------------------------------------------------------------