Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Anchors and Objects

0 views
Skip to first unread message

Webbiz

unread,
Dec 3, 2008, 12:43:49 PM12/3/08
to
Greetings.

This question is one I've had for a long time but never got around to ask.
Perhaps someone can DIRECT me to the line of study I need to accomplish what
appears to be a common programming task.

Some of my programs allow you to DRAW an item, such as a LINE.

Now drawing a line is no big deal.

But I was wondering about those that you can click on later and see that it
is SELECTED because a little box shows up on each end of the line. If you
click on either of those little boxes and while holding down the mouse move
it, the line will move and stretch with the mouse while the other end stays
put. Once you let go of the mouse, your line is now at a new location and/or
length.

This is so common I know everyone here knows what I'm talking about.

Click some item on your form and it highlights with a few anchor boxes. This
is much like VECTOR drawing from my paint program.

I'm not looking for someone to teach me how to do this, although I certainly
won't complain if someone did. :-) I'm actually looking for WHAT subject
this falls under so I can hunt down the right material and learn how to do
this.

Purpose: I have a stock charting program I wrote years ago and continue to
tinker/improve year after year. It is what I usually come here to ask
questions for. Learned alot writing it. However, the tools I draw on my
charts can be added or deleted, but they cannot be moved or stretched like
other charting programs allow. I sure would like to learn how to add this
functionality to my charts.

Thank you in advance! (to avoid numerous thank you posts that probably bugs
everyone.)

Webbiz

Larry Serflaten

unread,
Dec 3, 2008, 1:36:51 PM12/3/08
to

"Webbiz" <nos...@formethanks.com> wrote

> But I was wondering about those that you can click on later and see that it
> is SELECTED because a little box shows up on each end of the line.

<...>


> This is so common I know everyone here knows what I'm talking about.

> I'm actually looking for WHAT subject this falls under so I can hunt


> down the right material and learn how to do this.

If I had to guess, I'd say it falls under creating a form designer.

None the less, take note that (in VB at least) when you click on one
of those anchors, they all disappear leaving an adjustable outline to
indicate the size change. So really what you have are 8 little boxes on
the border of some object that have size arrows for mouse pointers.

Add a Picturebox to a new form and set its Appearance to 0. Then
paste in the code below and see what happens as you mouse over
the picturebox....

LFS

Private Sub Form_Load()

With Picture1
' .Appearance = 0 < SET IN IDE
.BorderStyle = vbBSNone
.AutoRedraw = True
.Width = 105
.Height = 105
.BackColor = vbHighlight
.MousePointer = vbSizeNESW
Picture1.Line (0, 0)-(90, 90), vbHighlightText, B
End With

End Sub

Bill McCarthy

unread,
Dec 3, 2008, 8:40:12 PM12/3/08
to
Hi Webbiz,

You're looking for info on interactive designers. Note this doesn't have to
be vector based drawing, it could be discrete layers like many of the raster
drawing programs use. For lines, using vectors is relatively simple maths
and you can determine if a mouse click is on a line given the line's start
and end points. For other shapes it becomes more complex, and you may want
to consider using regions and PtInRegion api etc.
Basically you need to store the information about your shapes in an array or
collection. Use the order of that array as your ZOrder. That is the first in
the list is the topmost. This means you can just grab the first match, but
that often results in a crude feeling UI, where the user has to click
exactly on an object. Fancier UI's will allow for a degree of error and try
to select the object with the least degree of error from the co-ordinates.
Again that is reasonably simple for simple shapes but gets very complex for
irregular shapes, so what you might see is the Ui more forgiving with simple
shapes than irregular ones.

"Webbiz" <nos...@formethanks.com> wrote in message
news:ozzZk.25209$Jl5....@newsfe19.iad...

Webbiz

unread,
Dec 4, 2008, 12:15:21 AM12/4/08
to
Interactive Designers?

I'll do a google on that and see what comes up. Thanks.

If anyone knows of a good source of information on that subject, please
point the way.

Thanks again.

(Note to Larry on his code in another message: Thanks for your comments and
the code. I tried it, but didn't get what it was suppose to convey to me.
All that happened was a form with a little square. You mouse over and the
cursor changes. Are you saying that those little squares you see on the ends
of the lines and around objects you can move and stretch and so-forth are
pictureboxes? And are you then suggesting that one can simply move the
picturebox to wherever and that where you finally stop moving it to becomes
the new coordinate for the object and you then do what needs to be done to
draw to that coordinate? Am I close in this assumption? Thanks again.)


"Bill McCarthy" <Bi...@localhost.com> wrote in message
news:ueYZLFbV...@TK2MSFTNGP04.phx.gbl...

Mike Williams

unread,
Dec 4, 2008, 7:16:45 AM12/4/08
to
"Webbiz" <nos...@formethanks.com> wrote in message
news:ozzZk.25209$Jl5....@newsfe19.iad...

> Some of my programs allow you to DRAW an item, such as


> a LINE. Now drawing a line is no big deal. But I was wondering
> about those that you can click on later and see that it is
> SELECTED because a little box shows up on each end of the
> line. If you click on either of those little boxes and while holding
> down the mouse move it, the line will move and stretch with the
> mouse while the other end stays put. Once you let go of the
> mouse, your line is now at a new location and/or length.

The first thing you'll need to do is to write some code that allows you to
detect which of your lines (or other objects) the user has clicked on, and
you'll need to do it in such a way that there is a bit of "leeway" so that
if the user clicks reasonably close to a line or other shape you will detect
it, otherwise the user will find that he needs to be "pixel perfect" with
his mouse when attempting to select something. For simple objects like
straight lines and rectangles this sort of detection (reasonably close to
the object) is fairly straightforward using a bit of math, but for more
complex shapes the math it is not so easy. You will also need to make sure
that your detection code runs through the various lines and other objects in
the reverse order that you drew them, otherwise you will often end up
detecting selection on the wrong object (one that is partially or wholly
hidden behind another).

One method which is not what most people would call "elegant" but which
eliminates the need for any math even on complex shapes and which should
work quite well and which should more or less automatically take care of the
things I have mentioned (clicking reasonably close to a shape regardless of
its complexity and the equivalent of the ZOrder stuff) is to draw each
object twice when you create your stock chart display, once into your main
display PictureBox and once into a hidden Autoredraw PictureBox. The outline
of the second drawing, or the actual line or rectangle itself if it is not a
filled shape, should be drawn into the hidden Autoredraw PictureBox using a
draw width two pixels greater than the draw width you used for that specific
object in the main display PictureBox (this facilitates the "approximately
on the line or shape" user selection).

Each line (or other object) you draw has to be assigned a number of course,
which you can store in an array of Longs or whatever, and you can use the
same number as the draw colour for the line or shape that you draw into the
hidden Autoredraw PictureBox (drawing the actual displayed object itself
into the displayed PictureBox at whatever colour you wish). Then you track
the mouse over the main displayed PictureBox using its MouseMove and Click
etc events but when the user clicks the button (to select an object) you
read the pixel colour at that position in the hidden Autoredraw PictureBox.
This colour will tell you the number of the "object" that the user clicked
on.

Naturally if you want this code to work on systems running at 16 bit colour
depth as well as the normal full colour depth then you will need to choose
object numbers (and therefore colour values) that are actually available on
a 16 bit display. Better still, you can use the full range of colours
(allowing you to use 1, 2, 3, 4, 5, 6, 7, etc for your object numbers and
colour numbers) by using a DIBSection instead of a hidden Autoredraw
PictureBox for your offscreen drawing. DIBSections are very easy to set up,
although you will of course need to draw into them using the equivalent API
drawing methods instead of the native VB drawing methods.

I haven't actually written any code along these lines (unless I did so many
years ago and my advancing years have caused me to forget!) but I imagine
that it should work okay. It should allow very easy "approximately selected"
detection and by its nature it should automatically take account of the
order in which you drew the objects. Once you've got the "clicked object
detection" off the ground it should be relatively simple to add code to
effectively move the shape in response to the user's movement of the mouse.
With lines and simple shapes (which is what you seem to require) you can
simply use such an object (VB Line or Shape Control) initially in your
drawing or otherwise "undraw" the existing line and create an equivalent
Line or Shape control in its place that the user can move, and for more
complex drawings you can "undraw" the existing shape and draw the moving
shape as a sort of "sprite".

Anyway, those are my initial thoughts on the subject. No doubt others will
have plenty of alternative suggestions for you.

Mike

Mike Williams

unread,
Dec 4, 2008, 7:26:48 AM12/4/08
to
"Webbiz" <nos...@formethanks.com> wrote in message
news:ozzZk.25209$Jl5....@newsfe19.iad...

> Now drawing a line is no big deal. But I was wondering about


> those that you can click on later and see that it is SELECTED

In my previous response I wrote, "Each line (or other object) you draw has

to be assigned a number of course,

which you can store in an array of Longs or whatever". I actually meant to
say, "which you can store in the appropriate element of an array of UDTs",
since you will of course need to store other details of the shape as well as
its "number".

Mike


Larry Serflaten

unread,
Dec 4, 2008, 8:12:35 AM12/4/08
to

"Webbiz" <nos...@formethanks.com> wrote

> (Note to Larry on his code in another message: Thanks for your comments and
> the code. I tried it, but didn't get what it was suppose to convey to me.
> All that happened was a form with a little square. You mouse over and the
> cursor changes. Are you saying that those little squares you see on the ends
> of the lines and around objects you can move and stretch and so-forth are
> pictureboxes? And are you then suggesting that one can simply move the
> picturebox to wherever and that where you finally stop moving it to becomes
> the new coordinate for the object and you then do what needs to be done to
> draw to that coordinate? Am I close in this assumption? Thanks again.)

You have the general concept correct. Those little boxes simply need to
be able to respond to mouse-over, and mouse-down events. Labels,
Image controls, and Pictureboxes all have the required events. If you
don't use a control for those boxes, then you'll end up having to track the
mouse every time something is selected to see if it is within one of those
boxes so you can change the cursor. OTOH, do you really need all 8
boxes, or would one box at the lower right corner suffice? (Kinda cheap
but it could work is some circumstances). Lines of course only need
2....

In the end its up to you according to how much effort you want to put
into it....

LFS


Webbiz

unread,
Dec 9, 2008, 8:42:06 PM12/9/08
to
Well, I read this a few times and I have to admit it flew right over my
head.

I suppose that means there are no "Object Select and Modify/Move for
Dummies" book available.

Thanks. :)

Webbiz


"Mike Williams" <Mi...@WhiskyAndCoke.com> wrote in message
news:ODpVjogV...@TK2MSFTNGP04.phx.gbl...

Bill McCarthy

unread,
Dec 9, 2008, 9:09:14 PM12/9/08
to

Hi Webbiz,

"Webbiz" <nos...@formethanks.com> wrote in message

news:K7F%k.4652$uS1...@newsfe19.iad...


> Well, I read this a few times and I have to admit it flew right over my
> head.
>
> I suppose that means there are no "Object Select and Modify/Move for
> Dummies" book available.
>
> Thanks. :)
>
> Webbiz

It's not really that hard. I know I wrote a flow diagram tool some dozen or
more years ago now. You can do it a variety of ways. I think I used
windowed controls as it made it easy to use an object orientated approach,
where each part of the diagram could respond to mouse clicks directly, draw
glyphs at it's corners and move as you held the mouse down. Joining lines
are more difficult. You can use windows for them, but you need to set the
window region. They also need to respond to the movement of the two objects
they connect. Alternatively you can have connecting lines as just an arrays
of structures telling you from what object to what object and redraw them
all when items get moved. The difficulty there is responding to a user
trying to select a line and that requires a bit of maths or creating of
regions and examine with PtInRgn etc.

The first thing to do is decide exactly what it is you are doing. Is it a
flow diagram, a random drawing program, etc ?

Webbiz

unread,
Dec 11, 2008, 12:00:44 PM12/11/08
to
Hello Bill.

Suppose you have a chart that displays stock prices as vertical bars,
whether they be OHLC or Candlesticks.

The chart is drawn on a PictureBox control.

Currently, you can scroll it, you can draw on it (the majority of my tools
are simply different ways to use LINES).

If someone wants to remove a line that was drawn earlier, he only needs to
right-click it. If it is uncertain which he is trying to delete due to
proximity, a box pops up so that he can choose.

What I'd like to do is simply be able to left-click on the line to 'select'
it, where you see a little box on each end appear. Then all one needs to do
is to click and drag one of those little boxes in order to lengthen the line
and drop it in a new location. If I want to simply move the whole line
without affecting the current angle of the line, then the click needs to be
somewhere on the line that is between those end boxes and not within the
boxes themselves. Then the person should be able to move the line, angle
intact, to a new location.

So I was curious as to how this is commonly done as it appears to be in many
charting applications I have found.

Hope this explains things a bit more. I know, it sounds all so basic, but
trust me, I'm not that clever. :-)

Thanks.

Webbiz


"Bill McCarthy" <Bi...@localhost.com> wrote in message

news:eJUJI7mW...@TK2MSFTNGP04.phx.gbl...

Larry Serflaten

unread,
Dec 11, 2008, 2:35:13 PM12/11/08
to

"Webbiz" <nos...@formethanks.com> wrote

> Suppose you have a chart that displays stock prices as vertical bars,
> whether they be OHLC or Candlesticks.

> Currently, you can scroll it, you can draw on it (the majority of my tools


> are simply different ways to use LINES).
>
> If someone wants to remove a line that was drawn earlier, he only needs to
> right-click it. If it is uncertain which he is trying to delete due to
> proximity, a box pops up so that he can choose.
>
> What I'd like to do is simply be able to left-click on the line to 'select'
> it, where you see a little box on each end appear. Then all one needs to do
> is to click and drag one of those little boxes in order to lengthen the line
> and drop it in a new location. If I want to simply move the whole line
> without affecting the current angle of the line, then the click needs to be
> somewhere on the line that is between those end boxes and not within the
> boxes themselves. Then the person should be able to move the line, angle
> intact, to a new location.
>
> So I was curious as to how this is commonly done as it appears to be in many
> charting applications I have found.
>
> Hope this explains things a bit more. I know, it sounds all so basic, but
> trust me, I'm not that clever. :-)


You might just keep things a bit simpler. Left button moves, right button
sizes, sort of thing. Rather than trying to get pixel perfect with little boxes
that may be as large as the lines they are trying to move.

Here's a sample you can try out, paste it into a new form....

LFS

Option Explicit
Private Type MinMax
min As Single
max As Single
End Type

Private Grp(0 To 5) As MinMax
Private Active As Long

Private Sub Form_Load()
Dim i As Long
ScaleMode = vbPixels
AutoRedraw = True
BackColor = vbWhite
Line (-1, 100)-(400, 100), vbBlack
Show
For i = 0 To 5
Grp(i).min = (Rnd - 0.5) * 8
Grp(i).max = Grp(i).min + Rnd * 4
Draw i, False
Next
End Sub

Private Sub Draw(ByVal Index As Long, ByVal HiLight As Boolean)
Dim idx As Long, max As Long, min As Long
idx = Index * 10 + 20
max = Grp(Index).max * 10 + 100
min = Grp(Index).min * 10 + 100
Line (idx - 4, 0)-(idx + 4, 200), vbWhite, BF
Line (idx, 0)-(idx, 200), vbBlack
If HiLight Then
Line (idx - 4, max)-(idx + 4, min), RGB(96, 96, 96), BF
Else
Line (idx - 4, max)-(idx + 4, min), RGB(64, 196, 64), BF
Line (idx - 4, max)-(idx + 4, min), vbBlack, B
End If
End Sub


Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim XX, YY

XX = (X - 15) \ 10
YY = (Y - 100) / 10
If (XX >= 0) And (XX <= 5) Then
If (YY >= Grp(XX).min) And (YY <= Grp(XX).max) Then
If Active <> XX Then
Draw Active, False
Active = XX
Draw Active, True
End If
End If
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim XX, YY, ZZ, SZ
XX = (X - 15) \ 10
YY = (Y - 100) / 10
If XX = Active Then
SZ = Grp(XX).max - Grp(XX).min
ZZ = SZ / 2 + Grp(XX).min
Select Case Button
Case vbRightButton
' Size
If YY > ZZ Then
Grp(XX).max = YY
Else
Grp(XX).min = YY
End If
Case vbLeftButton
' Move
Grp(XX).min = YY - SZ / 2
Grp(XX).max = YY + SZ / 2
End Select
Draw XX, True
End If
End Sub


Bill McCarthy

unread,
Dec 11, 2008, 10:13:11 PM12/11/08
to
Hi Webbiz,

If you've already got the code to determine which line they click on, then
really you've got the hardest part covered already.
The logic usually used is to allow selection, then in either a continuation
of the mouse movement or a spate mouse movement, move the line. That is
the user can let the mouse button go up an the line usually stays selected
until they click elsewhere.
So the actions are:
- on mouse down, determine the selected line. You've already got code for
this. Draw little boxes at the end. You may want to adapt that to include
selected line tracking. Eg, if the user mouse downs near a previously
selected line, select that line again.
Add some user friendly smarts to it by monitoring the mouse up and any mouse
move operations: e.g if they move the mouse and click again chances are they
are trying to select a different line that's nearby, but not if they have
just moved the currently selected lien or selected it the first time. Add
this last once you get the rest sorted, but IMO it's that kind of intuitive
UI that makes a lot of difference when working with lots of objects.
- on the mouse down, look at the length of the selected object. If it is
short then leave it as the entire line is selected, setting the pointer to
Size. But if it is say greater than 10 pixels long, then determine if they
clicked near the end. If so actually position the cursor on the end, and
setting the cursor to one of the size pointers based on the line gradient.
eg Size NE SW.
- record the mouse position in the mouse down, after you have determined if
you need to correct the mouse position.
- in the mouse move, if the left button is down start moving the line using
the difference in mouse positions. The difficulty here is screen flicker.
You may want to first start the movement by drawing the screen without the
line, then draw the line as you would a bounding box. This allows you to XOr
the line to erase it without having to redraw the entire picturebox region.
- in the mouse up, draw the line as you usually would.

"Webbiz" <nos...@formethanks.com> wrote in message

news:1Hb0l.9870$vI1...@newsfe03.iad...

Webbiz

unread,
Dec 13, 2008, 1:25:48 AM12/13/08
to
Bill, what do you mean by "then draw the line as you would a bounding box"?

BTW, thanks for the play by play. Very helpful. :-)

(To Larry: Thanks for your code example. Unfortunately, I need to adapt to
existing code where the right click is for deleting. So the move/stretch
would be the left click. Also, I'd like to do the little boxes as it is
common for this type of program. Again, thx.)


"Bill McCarthy" <Bi...@localhost.com> wrote in message

news:%23V$hTeAXJ...@TK2MSFTNGP02.phx.gbl...

Bill McCarthy

unread,
Dec 13, 2008, 1:54:16 AM12/13/08
to
Hi Webbiz,

"Webbiz" <nos...@formethanks.com> wrote in message

news:KzI0l.37626$yB4....@newsfe07.iad...


> Bill, what do you mean by "then draw the line as you would a bounding
> box"?
>

Rubber band box type effect like when you select items on the desktop. What
I specifically meant was set the drawmode to vbInvert (XOr), draw the line,
then whe nthe mouse moves you draw over that line and it restores the
previous background. Only when the mouse is released do you draw in the
usual pen.

Here' these are old, but they expalin the rubber band thing I meant :

http://support.microsoft.com/kb/71489
http://support.microsoft.com/kb/71488

> BTW, thanks for the play by play. Very helpful. :-)
>


You're welcome :)

Jeff at Bennet-Tec.com

unread,
Dec 13, 2008, 11:26:04 AM12/13/08
to
"Webbiz" wrote:

> . . .

> Some of my programs allow you to DRAW an item, such as a LINE.

> . . .

> But I was wondering about those that you can click on later and see that it
> is SELECTED because a little box shows up on each end of the line. If you
> click on either of those little boxes and while holding down the mouse move
> it, the line will move and stretch with the mouse while the other end stays
> put. Once you let go of the mouse, your line is now at a new location and/or
> length.

> . . .

> Purpose: I have a stock charting program I wrote years ago and continue to
> tinker/improve year after year. It is what I usually come here to ask
> questions for. Learned alot writing it. However, the tools I draw on my
> charts can be added or deleted, but they cannot be moved or stretched like
> other charting programs allow. I sure would like to learn how to add this
> functionality to my charts.

> . . .

Are you open to a 3rd party component that replaces picture box and quickly
gives the funtionality you are looking for ?

If this is an option for you You may want to take a look at
www.btis.com/btproducts/MetaDraw/WebSamples/Drawing/md3_demo.htm
You can right click on the web page to see the underlying VB Script code
which will also work the same in VB.

This illustrates use of our MetaDraw component which would allow you to add
Vector drawing type featues exactly as you describe. You can create initial
chart with your program code and then quickly and easily allow user to add
his own lines, shapes, text, as well as to select elements to move and/or
resize. Also undo / redo, zoom, scroll, save, reload, ...
To allow a user to draw a line, just set EditMode = 1 and now user can draw
with his mouse, to allow user to select, move, resize lines, set EditMode =
11. It's pretty easy.

I hope this is helpful to you.

Jeff Bennett,
Jeff [at} Bennet-Tec {dot] Com

* Bennet-Tec Information Systems, Inc
* www.Bennet-Tec.Com
RELIABLE Component Software
and Custom Software Development Services
TList™ / ALLText™ / MetaDraw™ / Web Signature™

============================

Eduardo

unread,
Dec 13, 2008, 9:36:00 PM12/13/08
to
"Webbiz" <nos...@formethanks.com> escribió en el mensaje
news:1Hb0l.9870$vI1...@newsfe03.iad...

> What I'd like to do is simply be able to left-click on the line to
> 'select' it, where you see a little box on each end appear. Then all one
> needs to do is to click and drag one of those little boxes in order to
> lengthen the line and drop it in a new location. If I want to simply move
> the whole line without affecting the current angle of the line, then the
> click needs to be somewhere on the line that is between those end boxes
> and not within the boxes themselves. Then the person should be able to
> move the line, angle intact, to a new location.

The following code emulates what VB does in the IDE:
(add some lines to a form from the toolbox and paste the code)

Option Explicit

Private mMovingLineName As String
Private mSelectedLineName As String
Private mClickY As Long
Private mClickX As Long
Private WithEvents mlblSelected As Label
Private WithEvents mlblSelected2 As Label
Private mshpSelected1 As Shape
Private mshpSelected2 As Shape

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then
If mSelectedLineName <> "" Then
Controls(mSelectedLineName).Visible = False
Deselect


End If
End If
End Sub

Private Sub Form_Load()
Me.KeyPreview = True

Set mshpSelected1 = Controls.Add("VB.Shape", "shpSelected1")
mshpSelected1.Shape = vbShapeSquare
mshpSelected1.Width = 100
mshpSelected1.Height = 100
mshpSelected1.BackStyle = 1
mshpSelected1.BackColor = &H8000000D
mshpSelected1.BorderColor = &H8000000E
mshpSelected1.ZOrder

Set mshpSelected2 = Controls.Add("VB.Shape", "shpSelected2")
mshpSelected2.Shape = vbShapeSquare
mshpSelected2.Width = 100
mshpSelected2.Height = 100
mshpSelected2.BackStyle = 1
mshpSelected2.BackColor = &H8000000D
mshpSelected2.BorderColor = &H8000000E
mshpSelected2.ZOrder

Set mlblSelected = Controls.Add("VB.Label", "lblSelected")
mlblSelected.Width = 100
mlblSelected.Height = 100
mlblSelected.BackStyle = 0

Set mlblSelected2 = Controls.Add("VB.Label", "lblSelected2")
mlblSelected2.Width = 100
mlblSelected2.Height = 100
mlblSelected2.BackStyle = 0
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single,
Y As Single)

Dim C As Control
Dim L As Line
Dim iSel As Boolean

mMovingLineName = ""
mSelectedLineName = ""
Deselect
For Each C In Controls
If TypeOf C Is Line Then
Set L = C
If LineIsClose(L, CLng(X), CLng(Y)) Then
mMovingLineName = C.Name
mClickX = X
mClickY = Y
SelectLine C
Exit For
End If
End If
Next

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
Dim L As Line

If mMovingLineName <> "" Then
Set L = Controls(mMovingLineName)
L.X1 = L.X1 - mClickX + X
L.X2 = L.X2 - mClickX + X
L.Y1 = L.Y1 - mClickY + Y
L.Y2 = L.Y2 - mClickY + Y
SelectLine L
mClickX = X
mClickY = Y
End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y
As Single)
mMovingLineName = ""
mClickX = 0
mClickY = 0
End Sub

Private Function LineIsClose(nL As Line, pX As Long, pY As Long) As Boolean
Dim dx As Single, dy As Single, t As Single
Dim iDistancePointLine As Long
Dim X1 As Long, X2 As Long, Y1 As Long, Y2 As Long

X1 = nL.X1
X2 = nL.X2
Y1 = nL.Y1
Y2 = nL.Y2

dx = X2 - X1
dy = Y2 - Y1
If dx = 0 And dy = 0 Then
dx = pX - X1
dy = pY - Y1
iDistancePointLine = Sqr(dx * dx + dy * dy)
Exit Function
End If
t = (dx * (pX - X1) + dy * (pY - Y1)) / (dx * dx + dy * dy)
If t < 0 Then
dx = pX - X1
dy = pY - Y1
ElseIf t > 1 Then
dx = pX - X2
dy = pY - Y2
Else
dx = pX - (X1 + t * dx)
dy = pY - (Y1 + t * dy)
End If
iDistancePointLine = Sqr(dx * dx + dy * dy)

LineIsClose = iDistancePointLine < 40
End Function

Private Sub SelectLine(nLine As Line)
mshpSelected1.Left = nLine.X1 - mshpSelected1.Width / 2
mshpSelected1.Top = nLine.Y1 - mshpSelected1.Height / 2
mshpSelected2.Left = nLine.X2 - mshpSelected1.Width / 2
mshpSelected2.Top = nLine.Y2 - mshpSelected1.Height / 2
mshpSelected1.Visible = True
mshpSelected2.Visible = True

mlblSelected.Left = mshpSelected1.Left
mlblSelected.Top = mshpSelected1.Top
mlblSelected2.Left = mshpSelected2.Left
mlblSelected2.Top = mshpSelected2.Top
mlblSelected.Visible = True
mlblSelected2.Visible = True
mSelectedLineName = mMovingLineName
End Sub

Private Sub Deselect()
mshpSelected1.Visible = False
mshpSelected2.Visible = False

mlblSelected.Visible = False
mlblSelected2.Visible = False
End Sub

Private Sub mlblSelected_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
mClickX = X
mClickY = Y
End Sub

Private Sub mlblSelected_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim L As Line
If Button = 1 Then
If mClickX <> 0 Then
mlblSelected.Left = mlblSelected.Left - mClickX + X
mlblSelected.Top = mlblSelected.Top - mClickY + Y
mshpSelected1.Left = mlblSelected.Left
mshpSelected1.Top = mlblSelected.Top
Set L = Controls(mSelectedLineName)
L.X1 = mlblSelected.Left + mlblSelected.Width / 2
L.Y1 = mlblSelected.Top + mlblSelected.Height / 2


End If
End If
End Sub

Private Sub mlblSelected2_MouseDown(Button As Integer, Shift As Integer, X

As Single, Y As Single)

mClickX = X
mClickY = Y
End Sub

Private Sub mlblSelected2_MouseMove(Button As Integer, Shift As Integer, X

As Single, Y As Single)

Dim L As Line
If Button = 1 Then
If mClickX <> 0 Then
mlblSelected2.Left = mlblSelected2.Left - mClickX + X
mlblSelected2.Top = mlblSelected2.Top - mClickY + Y
mshpSelected2.Left = mlblSelected2.Left
mshpSelected2.Top = mlblSelected2.Top
Set L = Controls(mSelectedLineName)
L.X2 = mlblSelected2.Left + mlblSelected2.Width / 2
L.Y2 = mlblSelected2.Top + mlblSelected2.Height / 2

Webbiz

unread,
Dec 17, 2008, 12:53:06 PM12/17/08
to
Thanks Eduardo.

Yes, this was what I was referring to. I'll now study the code and see if I
can figure out how to apply this to other shapes as well.

Thank you very much.

Webbiz

"Eduardo" <m...@mm.com> wrote in message
news:gi1res$l70$1...@news.motzarella.org...

0 new messages