アットウィキロゴ
Public Class Form1
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ofd As New OpenFileDialog
 
        'ダイアログの詳細設定(無くても良い)
        With ofd
            'ダイアログタイトル
            .Title = "開くファイルを選択してください"
            '初期のファイル名
            .FileName = ""
            'フィルターの何番目を既定値にするか
            .FilterIndex = 1
            'フィルター:ファイルの種類
            .Filter = "画像ファイル名(*.BMP;*.GIF;*.JPG;*.PNG)|*.BMP;*.GIF;*.JPG;*.PNG"
            '初期のフォルダー
            .InitialDirectory = "C:\"
        End With
 
        '「ファイルを開く」ダイアログを表示。
        If ofd.ShowDialog() = DialogResult.OK Then
            '選択されたファイル名を表示
            TextBox1.Text = ofd.FileName
            PictureBox1.Image = Image.FromFile(ofd.FileName)
        End If
 
        ofd.Dispose()
 
 
 
    End Sub
End Class

画像を読み込む時は Image.FileFrom(ファイル名)

PictureBoxのプロパティ SizeModeを弄ることで表示サイズ調整可能
AutoSize:pictureboxのサイズが自動的に合わせられる
Zoom:タテまたは横がPictureBoxサイズに合わせられ、画像の全領域が入る(縦横比固定)
StretchImage:画像サイズを縦横比込みでBOXに合わせる

Private Sub DrawTieLine(ByVal sender As Object, ByVal startP As Point, ByVal endP As Point)    '始点と終点の間に線を引く
        Dim g As Graphics = CType(sender, PictureBox).CreateGraphics
        Dim pp As New Pen(Color.Pink, 4)
 
        CType(sender, PictureBox).Refresh()
        g.DrawLine(pp, startP.X, startP.Y, endP.X, endP.Y)
 
        g.Dispose()
        pp.Dispose()
 
    End Sub
Picturebox.Refresh() によってDrawlineしたものを消せる(背景画で読み込んでいる物はそのまま)
最終更新:2009年11月18日 01:18