?
Solved

VB.net create lines on dragging

Posted on 2014-09-08
5
Medium Priority
?
155 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 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:Murray Brown
ID: 40311514
0
 

Author Comment

by:Murray Brown
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:Murray Brown
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:Murray Brown
ID: 40372379
thanks
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 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