LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Control Help: Draw a line and output start and end points

Solved!
Go to solution

I'm looking to find or make a custom control (or simple subVI) that will appear as a 100x100 unit grid and allow me to draw a line from one point to another on that grid. It will then output the (x,y) of the starting and end point of that line on the grid.  Any help or ideas?

 

Thanks,

 

Steve

LabVIEW 2009 SP1

0 Kudos
Message 1 of 5
(2,971 Views)

Check out XControls

=====================
LabVIEW 2012


0 Kudos
Message 2 of 5
(2,968 Views)
Solution
Accepted by topic author SteveKS

What you basically want is a loop with an event structure where you process Mouse Down, Move and Up events for your controls. There are any number of ways of implementing something like this, but this one will probably be the simplest:

 

  1. Use a multicolumn listbox or a table for your grid. Hide the scrollbars and headers.
  2. You can use the ActiveCell property with -2,-2 to select all cells. You can then use the cell size property to set the exact size of the cell.
  3. Next, you put a picture control on top of the table and color its background transparent so that the table shows through. You use property node to make sure the two are aligned to exactly the same spot and size.
  4. You use the mouse events on the picture control to detect the clicks and moves.
  5. You use the table's Point to Row Column method to translate the event's position data to a cell.
  6. You use the picture control VIs to draw the line on the picture based on that data.
  7. You can even color the selected cells in the table using the table properties.

If you want to simplify things somewhat, you can also use the timeout event instead of the Mouse Move event to draw the line, but then you'll need to keep the timeout value in a shift register and reset it to -1 (no timeout) when the Mouse Up event happens.

 

I would also suggest processing Mouse Enter and Leave events to change the cursor and cancel if the user leaves in the middle of dragging.


___________________
Try to take over the world!
Message 3 of 5
(2,952 Views)

Thank you for the guidance, as I think this has taken me down a path that will be successful for my needs.  One obstacle that I'm having a tough time working around however, is the pixel coordinates for the Point to Row Column feature. When I set the Multicolumn Listbox position to 240,240 let's say, it will position it that far from the origin of the VI window, but when I use the mouse and Point to Row Column, it is translating the pixel position relative to the upper left corner of the computer monitor, not the Listbox.  One solution I have in mind is if I could just add the position of the origin relative to the upper corner of the monitor to the Point to Row Column position, it would correct it.  I can't find this property though, if it exists. Any help on this solution or any other ideas?

0 Kudos
Message 4 of 5
(2,934 Views)

The mouse events should give you the coords relative to the origin of the pane, not the screen, so that should work the same no matter where the window is. Are you using the mouse input VIs instead? If that isn't it, you should post your code.

 

Even for the events, you might need to do some playing around with the numbers - if the position of your control is not on the origin, you will need to subtract that in order to know where to draw in the picture control and you would usually also need to account for the two or three pixels of the border of the control.

 

I don't think you can get a single property or method which will give you screen coordinates translation. You can get the info for the window, but translating that into something in your pane is unreliable.


___________________
Try to take over the world!
0 Kudos
Message 5 of 5
(2,923 Views)