Solved

VB.net create lines on dragging

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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