Windowsフォームで画像ファイルを表示する
単純な例
[VB2002][VB2003][VB2005]
PictureBox1.BackgroundImage = Image.FromFile("C:\Winnt\隅田川.bmp")
■リスト1:グラフィックスとして表示する例
[VB2002][VB2003][VB2005]
PictureBox1.Image = Image.FromFile("C:\Winnt\隅田川.bmp")
■リスト2:一度メモリーに読み込んでおく例
すばやく画像を切り替えたいときはこちらの方法が優れている。
[VB2002][VB2003][VB2005]
Dim MyImage As Image = Image.FromFile("C:\Winnt\隅田川.bmp")
PictureBox1.BackgroundImage = MyImage
■リスト3:Graphicsクラスを使う例
[VB2002][VB2003][VB2005]
Dim MyImage As Image = Image.FromFile("C:\Winnt\隅田川.bmp")
Dim ImagePoint As New Point(0, 0)
g.DrawImage(MyImage, ImagePoint)
■リスト4: 注意:この例では g を Graphicsオブジェクトとする。Graphicsオブジェクトをどのように取得するかはこの例では示されていない。 PictureBoxのPaintイベントの引数e.Graphicsとして受け取るのがセオリー。