-
draw line
i have made some code to create a line and set one end of it to the curunt
cursor location:
Code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
i = X
p = Y
a = a + 1
c = "g" & (a)
Set c = Controls.Add("VB.line", (c))
c.Visible = True
c.X1 = i
c.Y1 = p
the problem is that when i releese the mouse button i want to draw the other end of the line.
but when i say
Code:
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
c.X2 = i
c.Y2 = p
End Sub
an error comes up that says : "object required"
i know this is probebly a simple question but just can't figure it out!
thanx
mr smither
-
Re: draw line
didn't you mean to code:
c.X2 = X: c.Y2 = Y
C is a line control, correct?
Edited: C is dynamically created in the MouseDown event and its name is not c, is it? It is g# (some number). So you need to reference your line control with the correct name: g# (some number)
There should be other errors too. Are you using Option Explicit at the top of your form? Does your VB IDE options include "Require Variable Declaration"? If not, it should.
You can try this type of reference, but I do think you have other errors
Me.Controls("g" & a).X2 = X
Me.Controls("g" & a).Y2 = Y
-
Re: draw line
Unless there is a reason why you need to have line controls, you can use VB's Line method to draw lines. Try this and you might be pleased
1. Add a line to your form and name it Line1, make it's Visible property False
2. Make your form's AutoRedraw property True
3. Copy & paste this code to play with
Code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
With Line1
.X1 = X
.X2 = X
.Y1 = Y
.Y2 = Y
.Visible = True
End With
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Line1.Visible = True Then
Line1.X2 = X
Line1.Y2 = Y
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Line1.Visible Then
With Line1
Me.Line (.X1, .Y1)-(.X2, .Y2)
.Visible = False
End With
End If
End Sub
-
Re: draw line
thanx so mutch it works!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
thanx thanx thanx thanx thanx thanx