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:
Click the ‘Add Buttons’ button.
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.
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.
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...
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.
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?