Results 1 to 6 of 6

Thread: Drawing lines

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    103

    Question Drawing lines

    I am working on a program, just for fun, and have run into an issue I cannot resolve. The issue is simply this: When I try drawing a line over several Labels, the line only appears over the first Label.

    In an earlier version of the program, the Labels were Buttons, but based on some reading (which suggested that lines cannot be drawn over Buttons), I changed the controls from Button to Label, but that did not help.

    Attached is a simplified version of the code – I removed most everything I could and still have it function. To see the problem, run the program and then do this:
    1. Click the ‘Add Buttons’ button.
    2. Click at least two of the squares in the grid and note that all squares selected must have adjoining edges. Start with just two squares for simplicity.
    3. Click the ‘Build Path’ button.

    What happens is that when you click the squares in the grid, their location is noted. When you click ‘Build Path’, the routine buildPath_Click figures out the corners of the line (which should be a dashed line around/inside the selected squares), and then draws the line.

    Please don’t laugh too much at the code and please provide some suggestions as to how I can make this work.
    Attached Files Attached Files

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Drawing lines

    Every control has a Paint method. Who is running first? The Paint for the form or the Paint for the children?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    103

    Re: Drawing lines

    The Paint method is the form's, the lines are drawn within that Paint method, and there are no Paint methods associated with the children. The lines, however, have to cross multiple children, so I have no idea how to configure that...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Drawing lines

    Check this out:

    https://www.vbforums.com/showthread....n-All-Controls

    That demonstrates how to handle the Paint event of multiple controls and draw the same thing onto all of them.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    103

    Re: Drawing lines

    jmcilhinney - thanks. If you look at my code, you will see (on line 86) that I assign the paint handler to every label. That is, however, the Form's paint event - so I took the line drawing code, moved it into its own routine, and changed the AddHandler line to point to that routine. Did not help - same issue.

    I just tried adding a PictureBox to the form, making it the parent of each label, but that also didn't help.
    Last edited by groston; Mar 15th, 2023 at 10:31 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Drawing lines

    If it didn't work then you did it wrong. Show us what you did so we can see what you did wrong. I'm not interested in downloading a code file when there's no need. Post the relevant code directly.

    Do you want to draw on just the Label's or do you want to draw on their parent too? Are all the Labels directly on the form or are some or all of them in some other container? Are there any Labels you don't want to draw on in the same container?

Tags for this Thread

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