Solved

VB.net create lines on dragging

Posted on 2014-09-08
5
131 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now