Solved

VB.net create lines on dragging

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
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.

760 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

19 Experts available now in Live!

Get 1:1 Help Now