The following code will draw a rectangle in picture1 (the picturebox). Use the boolean value true for rect to draw a rectangle, or use false to draw a line. The forecolor of the picturebox will be the color of the line. You can use the RGB function to obtain the long value for the color you are wanting to fill your rectangle with or you can use a common dialog box (
). Hope this helps and good luck.
Global TempX As Long
Global TempY As Long
Public Sub ChooseFontColor()
' The following code will set the color of the line you are going to draw in the picturebox.
Dim e As New CommonDialog
e.DialogTitle = "Choose the Font Color"
e.ShowColor
Picture1.ForeColor = e.color
End Sub
Public Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Get the line's start point.
TempX = X
TempY = Y
End Sub
Public Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Get the line's end point and draw it.
' Use the RGB function as a temporary measure to obtain a long value fill color for the rectangle.
Picture1.Line(TempX,TempY,X,Y,True,RGB(100,100,100))
End Sub
PS: Use the SavePicture function to save what you've created.
Public Sub SavePicturebox()
Dim DC As New CommonDialog
DC.DialogTitle("Save Picture As:")
DC.showSave
If DC.FileName = "" Then
Msgbox "File was not saved: No file name provided"
Else
SavePicture (Picture1.Image, DC.FileName)
End If
End Sub