Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a Line Object

Status
Not open for further replies.

xspanner

Programmer
Jan 16, 2002
29
0
0
RO
Please anyone give me a code which creates a Line object on a Form for example when I click on the Form

I tried
Dim myline as Line
Set myline = Line and etc ..
but it does not work

Thnx
 
> a code which creates a Line object on a Form

1) add a line object, make it an array (set Index property to 0 - like line1 should become line1(0))
You can make it invisible or put out of bounds of form.
2) make a global var LC (LineCounter), set it to 0
3)
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
LC = LC + 1
Load Line1(LC)
With Line1(LC)
.X1 = X
.Y1 = Y
.X2 = X + Rnd * 1000 - 500
.Y2 = Y + Rnd * 1000 - 500
.Visible = True
End With
End Sub

Well, it was quick example - you have to tailor it to your needs.
 
Thanks, but i have to create up to 50 lines and they must be objects, because i have to save their positions.
thanks
 
Can't quite get it... please clarify:
> but i have to create up to 50 lines and they must be objects, because i have to save their positions.

either of ways suggested allow to create any (well, almost) amount of lines.
If you have to save positions - fine, store coords somethere (then restore if needed)...

So what are you actually trying to do?
 
thanks tsh73 now I draw lines and store coords in a file, BUT another problem came :

here is my code:

DrawWidth=4
ForeColor=vbRed
BorderStyle=3
Line(10,10)-(700,10)

the BorderStyle=3 line does not work because the form has a BorderStyle property too (fixedsyngle, double..etc), and it refers to it.

How can I "tell" VB that I refer to the lines' Borderstyle property?

 
Try to use
DrawStyle = 3
This is form attribute.
This thing works for lines drawn as line(x1,y1)-(x2,y2)
Actually I have to set DrawWidth to 1 to see it work. From the help:
----
If DrawWidth is set to a value greater than 1, DrawStyle settings 1 through 4 produce a solid line (the DrawStyle property value isn't changed). If DrawWidth is set to 1, DrawStyle produces the effect described in the preceding table for each setting.
----

The BorderStyle thing will work if you create line objects with Load statement.
Then you can use Line1(lc).BorderStyle
so Basic will know what object you are talking on. It will not work with DrawWidth>1 as well (at least it didn't at my machine.)

So it seems that there no easy way to draw dotted lines several pixels width.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top