Results 1 to 24 of 24

Thread: Line control

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    korea
    Posts
    9

    Question

    How can I make click event to Line control on runtime?

    I want to make simple cad

    please!!! hurry


    [Edited by holdu on 07-27-2000 at 10:14 PM]

  2. #2
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    No API needed

    [/code]
    Private MouseX as Integer
    Private MouseY as Integer

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

    Static LineBeingDrawn as Boolean

    LineBeingDrawn = Not(LineBeingDrawn)

    If LineBeingDrawn Then
    MouseX = X
    MouseY = Y
    Else:
    Form1.Line(MouseX, MouseY)-(X, Y)
    End If
    End Sub
    [/code]

    Hope it works!

    Thank you for listening,

    Me


    Courgettes.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    korea
    Posts
    9

    Re: No API needed

    That is just make line.
    I want click event on line like to cad program.
    please help me
    I don't care hard work...

  4. #4
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Question

    What exactly do you want?

    A line that moves around with the mouse until you click?

    I need a little more detail before I can give you the code.
    Courgettes.

  5. #5
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    A line doesn't have a click event. Either draw the line on a control that does have a click (like a picturebox) or use the forms_mousedown event to check where was clicked on the line.
    Or create a usercontrol (probably the easiest method) and create your own click event.
    Hope this helps

    Crazy D

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    korea
    Posts
    9
    Always thanks for your helps.
    Now, I need any-control that must have click event.
    I want to draw line and then retouch(cut, delete, move, reduce, graw,etc) on runtime, like to cad.

  7. #7
    Guest
    Not sure if this'll help, but its a cool feature . Kind of like V(ery) Basic's idea.

    Code:
    'add one line to your form one running the vertical length of your form
    'add a second line to your form running the horizontal width of the form
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y
    As Single)
    Line1.X1 = X
    Line1.X2 = X
    Line2.Y1 = Y
    Line2.Y2 = Y
    End Sub

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    korea
    Posts
    9
    Yes... I know this case.
    But, problem is how do computer know click on the Line control. Up-answer is next work(only move. how can we indicate line). When we just click on the Line, we can see any event.
    Very hard problem??
    Or, cann't solve??

  9. #9
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Oh, I get it now.

    You want to know when the user clicks on a line.

    There is some very long code to find this, which I made and then deleted a while ago (I'm that kind of irrational, moody person), but why do you need such a function? Other CAD apps don't use one.

    If you really need the code I'll be pleased to rewrite it for you.

    *wry smile*

    Just give the word,

    Moi.
    Courgettes.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    korea
    Posts
    9
    Oh... thanks for your kindness
    Now, I really need it....
    please...

  11. #11
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Give e-mail address and you'll have it within the Microsoft week.
    Courgettes.

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Don't wait up for it then
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  13. #13
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Microsoft Week = Anything between a month and a year

    (Just joking holdu, you'll get it)
    Courgettes.

  14. #14

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    korea
    Posts
    9
    Thank you everyone
    I got it this problem....

  15. #15
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Lightbulb Line Control "Click" event

    Is it SO difficult to understand the question?

    Dear Holdu,

    Yes indeed there's absolutely NO way to trigger the Click event for the Line control. BUT: there is an algorithm to create it, for ANY line which start and end coordinates are known.
    Have you ever heard of my friend BRESENHAM? (probably dead)

    The "Bresenham algorithm" is a standard algorithm to create lines, circles, ... via the setting of dots. So, if you can set the dots, you can also use this algorithm to check out if a mouse click (or even: Move) happened on a line.
    Use this algorithm and for every dot drawn (or: calculated, you do not really want to draw it) you check if you Mouse X and Y corresponds with the calculated dot coordinates.
    If so, stop the algorithm and simply return with the message that YOU CLICKED ON A DOT!
    This algorithm is very fast, in fact, on a Pentium you won't even notice the calculating delay!
    So, if you're interested, I can send you this algorithm. It's not big code (just some lines).
    Bye,

  16. #16
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Ermm.

    I'm already making the class module for him. I didn't find out about the algorithm, so I made one myself

    It's more of a semi-algorithm, using SetPixel. On my little 200mHZ, 32MB RAM machine, you can't notice the delay at all.

    If holdu waits a couple of days and gives me an e-mail address, I can send the whole project to him (with Move, Delete, Grow, Reduce, Rotate etc.)

    I'll make it in time, holdu! I've done make line, Move and delete already.
    Courgettes.

  17. #17

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    korea
    Posts
    9

    Re: Line Control


    I found how to solve for this problem. But this way is not easy.
    I use line1.x1, x2, y1,y2, and mouse event....


    [email protected]



    [Edited by holdu on 08-07-2000 at 08:39 PM]

  18. #18
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Angry Patience, holdu, patience

    Arrgggggh!

    I'm making a ****ing class ****ing module, so if you'd be patient enough to wait a couple of days I'll give it to you.
    Its got Cut, Copy, Delete, Move (which is pretty ****ing cool at the moment), Enlarge and Reduce. So if you just wait and give me your e-mail address I'll send it to you. Its taken me a while, so it's probably got more features than yours.

    Just take a look bu giving me your ****ing e-mail!
    Courgettes.

  19. #19
    New Member
    Join Date
    Feb 2000
    Location
    San Diego
    Posts
    3

    Question Am I too late!? (Wait for me!)

    Sup guys,

    I've read the thread and im on the same boat as Holdu. Im working on a math/CAD-like proggy that will allow the user to draw poly shapes. The proggy would then, based on the drawn shape(s), spit out missing sides and/or angles, vector additions, areas, etc. The 'math' part, you can say that i got a pretty good handle on it, and that which i dont know i can easily learn from my Physics/Math courses/books. What i do need to know is, how to manipulate lines, ultimately to allow the users to re-define their 'shapes'. So far i've given the user the ability to make lines by manipulating a LINE CONTROL. I then use the LINE CONTROL's properties to create a LINE METHOD on the form(which can also be a picturebox). Wow they can make lines! Thats all fine n dandy but the hard part is trying to manipulate those LINE METHODS.

    As an example: The user will create a triangle with three lines (what were you expecting, 5 lines?). He will specify one angle on it and, maybe, the length to 2 legs. The program would then calculate the other 2 angles and missing length. But, now he wants to c how the calculations will turn out if the degree of the given angle is, say, 5 greater. He would need to click on the corresponding angle and change it (by drag or pull). So, he needs to be able to manipulate the triangle to recalculate for the same shape but different size.

    Did that make sense? No? ...too bad j/k If u want me to explain more let me know, but BASICALLY what im after is the code your writing for Holdu. So, if u can plz help out a poor VB soul


    PS: [email protected]


    - Evol

  20. #20
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    The code I wrote for holdu needs VB6 and it's essentially what the line control looks like at design-time at runtime (hard to understand )

    I'll send it to you, but I'm not sure it's what you want.
    Courgettes.

  21. #21

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    korea
    Posts
    9

    Smile Re: Am I too late!? (Wait for me!)

    I can't english very well. so I afraid that you don't understand my think and I can't unerstand your write..

    Uhm... I got cod to V(ery) Basic guy.
    That is very usefull. Then I modified for my program.
    May be you need V(ery) Basic guy's. If you want it, I will send you..

    Of course, V(ery) Basic guy must permit.... you know



  22. #22
    New Member
    Join Date
    Feb 2000
    Location
    San Diego
    Posts
    3

    Lightbulb Yup.

    lol everyone thinks i dont need this code? y? if anything im probably have more use for it than u guys. (im just saying). ill explain the application one more time.
    have u ever had a math class? im assuming 'yes'. Ok, now remember when you had to draw triangels and rectangles, squars... and angels... u had to wip out ur protractor and/or ur ruler right? then u would measure lengths and angels and what not. well my app will do all that on the computer! so instead of putting down ur ruler and drawing a 5 inch line, in my app u will just draw a line and as u drag it its gonna have like a lil tooltip saying what the current lenght of the line being made. so far i can do this, but now the you want to change that 5inch line to, say, 10 inches... instead of clearing the drawing u will b able to drag the line 5 more inches to reach 10 inches... now this drag method (sizing method) is what i need to figure out how to do.
    (v)ery your code lets you do this, but im having a hard time figuring it out... its kinda advanced for me, but im going line by line. the specific place where i have trouble is trying to understand event creation... like for the line. ur CLS files define methods and properties and other stuff about the line. this is something new to me.
    if u, or u guys, can plz help me understand the subject. this is just to speed things up, w/in time ill figure out the code u sent me. thnx again.

    - Evol

  23. #23
    Member
    Join Date
    Jul 1999
    Posts
    42

    Line control

    ' Paste this code in a VB Form containing a line control ' named Line1
    ' The Hit routine will calculate the distance from the mouse ' pointer to the line control
    Option Explicit

    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Hit(Line1, X, Y) Then
    MsgBox "HIT"
    End If

    End Sub

    Private Sub Form_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Hit Line1, X, Y
    End Sub

    '
    ' Hit will return true if (X,Y) is close enough to the line (Distance (X,Y)to line < 20
    '
    Function Hit(L As Line, X As Single, Y As Single) As Boolean
    Dim tx As Single, ty As Single
    Static XX As Single, YY As Single
    Dim Distance As Single

    ' Parameterized line
    tx = (X - L.X1) / (L.X2 - L.X1)
    ty = (Y - L.Y1) / (L.Y2 - L.Y1)
    ' Reset form and color
    Me.Cls
    L.BorderColor = RGB(0, 0, 0)

    ' Inside hit area if 0 <= tx <= 1 and 0 <= ty <= 1
    If tx < 0 Or tx > 1 Or ty < 0 Or ty > 1 Then

    Else
    XX = (X + L.X1 + ty * (L.X2 - L.X1)) / 2
    YY = (Y + L.Y1 + tx * (L.Y2 - L.Y1)) / 2
    Me.Line (X, Y)-(XX, YY)
    Distance = Sqr((X - XX) ^ 2 + (Y - YY) ^ 2)
    Hit = (Distance < 20) ' 20 is choosen randomly (smaller number will giver closer hits to the line
    If (Distance < 20) Then L.BorderColor = RGB(255, 0, 0)
    End If

    End Function

  24. #24
    Guest
    Alfred:

    Nice code, but if you want to have fun, try a VERTICAL line with your code...

    Sorry 'bout that...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width