/* WebClientによるネット上リソースの利用 2005/10/22 宍戸 輝光 */ using System; using System.Drawing; using System.IO; using System.Net; using System.Windows.Forms; public class netbmp:Form { private Bitmap m_bmp; private TextBox m_tbUri; private Button m_btLoad; netbmp() { Size = new Size(400, 400); m_bmp =null; // URI入力欄生成 m_tbUri = new TextBox(); m_tbUri.Width = 300; m_tbUri.Left = 96; m_tbUri.Top = 4; // Loadボタン生成 m_btLoad = new Button(); m_btLoad.Text = "Load"; m_btLoad.Left = 4; m_btLoad.Top = 4; // Loadボタンクリックイベント処理デリゲート設定 m_btLoad.Click += new System.EventHandler(this.LoadButton_Click); Controls.Add(m_btLoad); Controls.Add(m_tbUri); } // Loadボタンクリック処理 private void LoadButton_Click(object sender, System.EventArgs e) { // URI取得 String stUri = m_tbUri.Text; // WebClient生成 WebClient wcLoader = new WebClient(); // 指定URIからデータを読み込むストリーム生成 Stream srLoad = wcLoader.OpenRead(stUri); // ストリームからBitmap作成 m_bmp = new Bitmap(srLoad); // ストリームを閉じる srLoad.Close(); // フォームを再描画して、作成したBitmapを表示 Refresh(); } // フォーム描画 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // Bitmap描画 if (m_bmp != null) { /* Bitmapをフォームに描画 */ e.Graphics.DrawImage(m_bmp, 0, 40); } } public static void Main() { // フォーム生成 netbmp app = new netbmp(); // イベントループに入る Application.Run(app); } }