Solved

VB.net create lines on dragging

Posted on 2014-09-08
5
136 Views
Last Modified: 2014-10-10
Hi

I want to create a form that allows the user to connect different tables columns similar to that
in the image. What code would I use to draw the line when the user drags from one column name to another
0
Comment
Question by:murbro
  • 4
5 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40311183
And the image is... where?

I suppose that you want to do what is seen in many Microsoft interfaces (be it Access Relations, SQL Server Diagrams, Visual Studio XML Designers). The basic code to draw the line is quite easy. This is usually done in the Paint event of the Form or the control in which you display your tables:

Dim pen As New Pen(Color.Black)
e.Graphics.DrawLine(pen, x, y, x1, y1)

OnPaint is called whenever the form needs to redraw itself. It is called automatically in some situations, such as when the Form is covered by another one and the user brings it to the forefront. But you can force it to do so by calling Refresh on the Form or control when you detect a Drag.

In there, e.Graphics is passed as a parameter to the Paint method and represents your tool to draw on the Form or control.

x and y are the starting position of your line in pixels, relative to the upper left of the Form or control. x1 and y1 are the ending point of your line.

The hard part is to determine x, y, x1, y1. It depends on how you display your tables on the screen. You usually record x and y on the MouseDown of the starting control, save them in a Point variable at the form level, and reuse them along x1 and y1 on the MouseUp of the destination control.
0
 

Author Comment

by:murbro
ID: 40311514
0
 

Author Comment

by:murbro
ID: 40311517
Hi. Apologies. The image that I just put up is similar to the one I originally wanted to post but can't find now. Essentially it is very similar to the Access query builder
0
 

Author Comment

by:murbro
ID: 40311528
Could you perhaps just tell me what the VB.net code would be to draw one line. Thanks
0
 

Author Closing Comment

by:murbro
ID: 40372379
thanks
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question