|
分類:[VB.NET/VB2005]
タイトルが最大入力可能数を超えたので改めて書きますが、
ピクチャボックス(PicWaku)内にグラフィックで書いた線などの下側にJPEGなどの画像ファイルを呼び出したいのですが、画像ファイルがグラフィックで書いた線の上になって線が消えてしまいます。
Public Class Form1
Inherits System.Windows.Forms.Form
Dim gra As Graphics
Dim drawFlg As Boolean
Dim x1 As Integer = -1, y1 As Integer
Dim x2 As Integer = -1, y2 As Integer
Dim mypen As New Pen(Color.Black, 2)
(中略)
'起動
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
With picWaku
.Image = Nothing
.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
.Image = New Bitmap(picWaku.Width, picWaku.Height)
gra = Graphics.FromImage(.Image)
gra.Clear(Color.White)
End With
End Sub
Private Sub PicWaku_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PicWaku.MouseMove
If drawFlg = True Then
gra.DrawLine(mypen, x2, y2, e.X, e.Y)
x2 = e.X : y2 = e.Y
picWaku.Refresh()
End If
End Sub
Private Sub PicWaku_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PicWaku.MouseUp
drawFlg = False
picWaku.Refresh()
End Sub
Private Sub PicWaku_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PicWaku.MouseDown
x2 = e.X : y2 = e.Y
drawFlg = True
End Sub
'画像を呼び出すボタン(cmdRoad)
'このボタンを押したとき、マウスで書いた図形の下に画像を呼び込む
Private Sub cmdRoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRoad.Click
Dim MyPath As String = Application.StartupPath
Dim inifilepath As String
If MyPath.EndsWith("\") = False Then
MyPath &= "\"
End If
inifilepath = MyPath & "seikai.jpg"
If System.IO.File.Exists(inifilepath) = True Then
PicWaku.Image = Image.FromFile(inifilepath)
'PicWaku.Image = PicWaku.Image
End If
End Sub
'終了するボタン(cmdExit)
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
Application.Exit()
End Sub
Dim gra As Graphics
の gra を上手く使えば出来そうですが。
アドバイスをお願いします。
|