Results 1 to 4 of 4

Thread: draw line

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    126

    Question 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
    he is a good friend that speaks well of us behind our backs

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Last edited by LaVolpe; Feb 27th, 2009 at 10:06 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Posts
    126

    Re: draw line

    thanx so mutch it works!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    thanx thanx thanx thanx thanx thanx
    he is a good friend that speaks well of us behind our backs

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