Does anyone know how to create a shape at runtime
user enters x1,y1,x2,y2 and shape in text boxes and the shape appears on the form.
Printable View
Does anyone know how to create a shape at runtime
user enters x1,y1,x2,y2 and shape in text boxes and the shape appears on the form.
Make an array of shapes, then you can load them at runtime...;)
This code originally appeared in a post by toughcoder. I have just modified it a little.
OK, I have done this but I get a 'Object variable or with block variable not set'
Code:Option Explicit
Dim blnDrawing As Boolean
Dim x1 As Single, y1 As Single
Dim Shape2(1) As Shape
Private Sub Form_Load()
' Shape2.FillStyle = vbFSTransparent
' Shape2.FillColor = 0
' Shape2.BorderStyle = 1
' Shape2.BorderWidth = 1
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
x1 = X
y1 = Y
Shape2(0).Left = x1
Shape2(0).Top = y1
blnDrawing = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDrawing = True Then
Shape2(0).Width = X - x1
Shape2(0).Height = Y - y1
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnDrawing = False
Shape2(0).FillStyle = vbFSSolid
Shape2(0).FillColor = vbRed
Shape2(0).BorderColor = vbRed
End Sub
Sorry, I can't test this now(no IDE in my office), but
Put a shape on the form at designtime(.index=0)
at runtime use
VB Code:
shape(1).load
I hope that'S correct!
This thread kind of answered it for me
http://www.vbforums.com/showthread.p...1&goto=newpost
....LOL...nice bug with the visiblity....I remember the first time I did that...