|
-
Mar 13th, 2003, 07:22 AM
#1
Thread Starter
Fanatic Member
cannot create shapes at runtime. **RESOLVED**
This code originated from a post by toughcoder, I have modified it a little.
The bit I can't work out is I am getting an error message 'Object variable or with block variable not set.
Code:
Option Explicit
Dim blnDrawing As Boolean
Dim x1 As Single, y1 As Single
Dim Shape2 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.Left = x1
Shape2.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.Width = X - x1
Shape2.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.FillStyle = vbFSSolid
Shape2.FillColor = vbRed
Shape2.BorderColor = vbRed
End Sub
Any ideas.
Last edited by davidrobin; Mar 13th, 2003 at 07:45 AM.
-
Mar 13th, 2003, 07:35 AM
#2
You need to set the Shape object to something before you can reference it.
VB Code:
Set Shape2 = Controls.Add("VB.Shape","Control" & Controls.Count)
Do that before you attempt to set any of the shape's properties.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 13th, 2003, 07:38 AM
#3
And in the mouse move event, set the control to visible
VB Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnDrawing = True Then
Shape2.Width = X - x1
Shape2.Height = Y - y1
Shape2.Visible = True '[COLOR=red]<--- Added[/COLOR]
End If
End Sub
-
Mar 13th, 2003, 07:42 AM
#4
Thread Starter
Fanatic Member
Thanks MarkT,
The visible bit was confusing me, I couldn't tell if it was working or not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|