アプリ版:「スタンプのみでお礼する」機能のリリースについて

vb2005でformのload時に四角形を書く処理をしたいのですが
ボタンの中にコードを書かないと作画しないのですが
なにか方法がありますか。

現在のロジック
form1.load
Dim g As Graphics = PictureBox1.CreateGraphics()
Dim p As New Pen(Color.Black, 1)
g.DrawRectangle(p, 10, 20, 100, 80)
p.Dispose()
g.Dispose()
end sub

A 回答 (1件)

こんにちは、



pictureboxのpaintを利用します。

Public Class Form1

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

e.Graphics.DrawRectangle(Pens.Blue, 10, 10, 200, 200)

End Sub
End Class

この回答への補足

ありがとうございました。うまくいきました。

この処理の後、線を追加作画(2回)したいのですが
下記ロジックで.Image = のところはどう定義したらいいでしょうか。
Private Sub Button1_Click
ret = en(PictureBox1)
End Sub

Private Function en(ByVal o As PictureBox)
Dim g As Graphics
Dim p As New Pen(Color.Black, 1)
With o
     .Image = New Bitmap(.Size.Width, .Size.Height) <--新規ならこれでいいと思うのですが
g = Graphics.FromImage(.Image)
End With
For i = 1 To 9
x1,y1,x2,y2計算
g.DrawLine(p, x1, y1, x2, y2)
Next i
g.Dispose()
p.Dispose()
End Function

補足日時:2006/11/20 15:39
    • good
    • 0
この回答へのお礼

解決できました。
ありがとうございました。

お礼日時:2006/11/20 15:52

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!