WebBrowserコントロール
C#2.0の目新しい機能はだいたい弄ってみたので、そろそろGUI関連に手を出してみます。.NET2.0では念願のWebBrowserコントロールがサポートされ、アプリケーションに手軽にWebブラウザ機能をつけることが出来ます。画面からフォームにWebBrowserコントロールを貼り付け、URL入力用のエディットボックスとボタンを追加。で、下記コードで簡易ブラウザのできあがり。うーん、簡単すぎる。(笑)
#region Using directives using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; #endregion namespace WindowsApplication1 { partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { webBrowser1.Url = textBox1.Text; } } }
自動生成されるコードはパーシャルクラスで別ファイルになっているので、ソースがスッキリしていますね。