[Help] make a picture box appear on the forum when clicked

12padams

Well-known member
Joined
Feb 19, 2010
Messages
48
Programming Experience
Beginner
basically I am trying to expand my skills in visual basic 2010 and i want to find out how to make a kind of drawing program.

The idea is when you click somewhere on the form a bit of dirt will appear at the location of the mouse.

This code that I wrote did not seem to work:

VB.NET:
Public Class city

    Private Sub city_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click

        Dim dirt As New PictureBox
        dirt.Show()
        dirt.Image = My.Resources.dirt
        dirt.Location = New Point(MousePosition)
        dirt.Size = New Size(100, 100)

    End Sub
End Class
 
You have to add the PictureBox to the form's Controls collection for it to be displayed on the form. You should set all its properties first, then add it. There's no need to call Show because it will be visible by default.

By the way, if you're using VB 2010 then you might want to update your profile to indicate that you're using .NET 4.0, assuming that you are indeed using .NET 4.0.
 
Back
Top