How can I able to see the image in my picturebox?

那年仲夏 提交于 2019-12-14 02:29:31

问题


I have used the following code to draw what I want but when I used this code I cannot see the image I set on my picturebox. What should I do to draw on the picture box with an image? Please help me with this.

Public Class Form1
Dim draw As Boolean
Dim DrawColor As Color = Color.Black
Dim DrawSize As Integer = 6
Dim bmp As Bitmap




Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    cbxSize.SelectedIndex = 2
    bmp = New Bitmap(pbDraw.Width, pbDraw.Height)
    pbDraw.Image = bmp
    Dim down = False

End Sub
Private Sub PaintBrush(X As Integer, Y As Integer)
    Using g As Graphics = Graphics.FromImage(pbDraw.Image)
        g.FillRectangle(New SolidBrush(DrawColor), New Rectangle(X, Y, DrawSize, DrawSize))

    End Using
    pbDraw.Refresh()

End Sub

Drawing event

Private Sub pbtest_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles pbDraw.MouseDown
    draw = True
    PaintBrush(e.X, e.Y)
End Sub

Private Sub pbtest_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles pbDraw.MouseMove
    If draw = True Then
        PaintBrush(e.X, e.Y)
    End If
End Sub

Private Sub pbtest_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles pbDraw.MouseUp
    draw = False
End Sub

Please help me

来源:https://stackoverflow.com/questions/52505087/how-can-i-able-to-see-the-image-in-my-picturebox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!