Forms Drawing Problem

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
Hi.
I have a problem with drawing on forms.
I use a form (with showdialog) to add forms in a main form that is shown behind the showdialog form.
The problem is that when i use the graphics.drawline to draw lines between the forms, it only works AFTER i close the showdialog form.
(meaning that if i use the function again when i close the dialogform, then it works)
.
I see that it works when i use the function to draw the forms inside the main forms Paint event.
I don't wanna do that cuz i use other functions to draw, when a form is moved or resized. Think of it like the Relationship lines in an Office-Access Application.
Bottom line is, how can i make a line show at the main form when i call it from my showdialog form, WITHOUT having to use mainforms Paintevent.
P.S.
I use painteventargs in my functions in order to draw the lines like this:

VB.NET:
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] DrawLinePoint([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] PaintEventArgs, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] pMain [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Point, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] pSec [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Point)
[/SIZE][SIZE=2][SIZE=2]e.Graphics.DrawLine([/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Pen(Color.Black), pMain, pSec)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/SIZE]
it works(when the showdialog form is active) only when i put the function to run from the mainforms Paint event and not when i call it individually.
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
It's not going to work because all painting should be done with the graphics object supplied by the paint event, even if the actual code for the painting doesn't reside in that sub routine. You can simply pass it to your subfrom the paint event. Failing that the only other wat would be to create a graphics object from the hWnd or the Dc

VB.NET:
Dim G as graphics = Graphics.FromhWnd(YourForm.Handle)
 
Or
 
Dim G as graphics - graphics.fromhDc(Inptr that points to your forms device context)


Personally i'd stick to the paint event, why wouldn't you want to use it if it works. You can always call me.Invalidate to force a repaint of the form whenever necessary.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
Im not realy sure that the paint event will use the function that i call or all the functions that reside inside it. I don't just have 1 function for painting.
l will try your code and then i'll try to put all the functions in the paint event. I have tried to put a boolean to control the functions but since the paint event is using itself constantly i'm not sure how to control it.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
i'm trying the
VB.NET:
 Dim G as graphics = Graphics.FromhWnd(YourForm.Handle)
it does not work.
YourForm is the shodialogform or the mainform.
I'm assuming the showdialog form.
But it does not work , or i'm using it wrong.
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Grr [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Graphics = Graphics.FromHwnd(Showdialogform[/SIZE][SIZE=2].Handle)
[/SIZE][SIZE=2][COLOR=#008000]' Dim grr As Graphics
[/COLOR][/SIZE][SIZE=2]' i also used this... Grr = showdialogform[/SIZE][SIZE=2].CreateGraphics
[/SIZE]
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
VB.NET:
Private PaintALine as Boolean
 
Protected Overiddes Paint(byval Sender as object, byval e as PaintEventArgs)
 
Mybase.OnPaint(e)
 
If Me.PaintALine Then
Me.DrawMyLine(e.graphics)
End If
 
End Sub
 
 
 
Private Sub DrawMyLine(byval e as graphics)
 
e.drawline(Pens.Black,50,50,100,50)
End Sub
 
Private Sub MakeLineAppear
Me.PaintALine = true
Me.Invalidate
End Sub
 
Private MakeLineDisappear
Me.PaintALine = False
Me.Invalidate
End Sub

The above example is a very simple way of controling the paint event with conditional statement. If you call the MakeLineAppear sub from a button click or somthing then a line will appear on the for at the co-ordinates i have specified. If you then call the MakeLineDisappear Sub the line will er.. disappear. This is because you are changing the boolean varaible that is the condition that is tested for inside the paint event then calling Me.Invalidate forces a repaint of the form.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
Hi.
Your example does not work.
(i guess you wanted to write overrides onpaint etc, i've corrected but it does not work)
I've also used "New Pen" but nothing...
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
What bit about it doesn't work? You may need to add the following in the forms contructor...

VB.NET:
Mybase.SetStyle(ControlStyles.AllPaintingInWM_Paint,True)
Mybase.SetStyle(ControlStyles.DoubleBuffer, True)
Mybase.SetStyle(ContrlStyles.UserPaint,True)

There's is nothing wrong with my code and it should work just fine. Try adding the above lines in the forms contructor and if it still doesn't work then post the project and i'll tell you why. However as i have said, there is no reason why it should not work if you have placed the code inside the overriden paint event.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
I've written the exact code on a new application and added the extra code you gave me below the forms designer "after Me.ResumeLayout(False)"
I press the button but it does not do anything.
Also the problem i have is that even if it draws a line, when i want to add another line in the form it will erase the line that is drawn. I don't want this to happen.

 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
It won't erase that line if you don't change that boolean to false, or you can just create a array of Point structures and pass it to the drawlines method. Post the project and i'll take a look.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,605
Location
Norway
Programming Experience
10+
Also the problem i have is that even if it draws a line, when i want to add another line in the form it will erase the line that is drawn. I don't want this to happen
Drawing with Paint event isn't persistant, each time Paint happens it will repaint the full surface by the drawing specifications given. If you need to persist drawing you must either (A) keep collection of drawing objects that will be drawn each time Paint event occurs or (B) draw to an bitmap and display that image. You can combine A and B for a combination of persistant and non-persistant graphics.
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
As i said, if you create an array of Point Structures as a class level variable you can add to those points at will from anywhere. Then when you call invalidate the drawlines method will draw a line through all the points in the array. You don't necessarily need a collection of drawing objects here, or to go as far a bitmap.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
Hi.
Listen i solved the problem BUT LISTEN TO THIS!
1st i had my form show up before i draw. Let's say that this is somewhat logical.
2nd if you have breakpoints and some of them hit then the lines will not draw!!!!!!!!!!!!!!!!!!!!! Unbelievable! Microsoft did it again!! (i have 2005 team edition).
Now about the paint object. I don't use it. I use graphics directly. The problem is that you have frigtened me with what u said about lines that will be removed. Does this aplly also if you don't use the paint object (thus painteventargs) or i'm cool now?
Thanks.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,605
Location
Norway
Programming Experience
10+
If you use CreateGraphics for drawing to a control you're far worse in trouble, because you will have lost contact with the paint events totally and when this happens it repaints fresh (empty) over your graphics without you knowing (and this could happen many times a second). Work with the flow instead of agains it.

Breakpoints during live painting doesn't work very well for obvious reasons.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,605
Location
Norway
Programming Experience
10+
As i said, if you create an array of Point Structures as a class level variable you can add to those points at will from anywhere. Then when you call invalidate the drawlines method will draw a line through all the points in the array. You don't necessarily need a collection of drawing objects here, or to go as far a bitmap.
An array of Point Structures or similar will serve fine for my general term "collection of drawing objects". It's anyway just the methology for dynamically painting what you request each time the paint event happen.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
Can you give me an example?
Let's say that i have the line coordinates between my forms in an arraylist or a dataset.
Ok the paint event hits multiple times. What must i do? Have in mind that i want to paint and remove the lines when the forms move (locationchange and sizechange events).
Also what am thinking is that everytime i draw a line and let's say have a function that is called inside paint, the function will call some coordinates to draw. Ok what will happen to the previous coordinates i had? Will they stay? Will they be erased?
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
sapator said:
Will they stay? Will they be erased?
I beleive JohnH answered that already:
Drawing with Paint event isn't persistant, each time Paint happens it will repaint the full surface
Bob Powell has a good set of tutorials for understanding GDI+, it can be found here: Bob Powell's Beginners Guide to GDI+
sapator said:
I use a form (with showdialog) to add forms in a main form that is shown behind the showdialog form.
I'm really not following what you're doing. Perhaps you could explain the purpose of the application.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
I beleive JohnH answered that already:
Bob Powell has a good set of tutorials for understanding GDI+, it can be found here: Bob Powell's Beginners Guide to GDI+I'm really not following what you're doing. Perhaps you could explain the purpose of the application.

Thanks for the tutorial, i'll look into it.
Yes i can explain. Think of it as the query designer in Access. A form is shown(showdialog) and you select the table which is added in the backgroung along with other tables with lines showing the relations.
(actually i used dialogresponse and i remove the showdialog forrm now. If i want to add another table i reopen the showdialogform).
The problem i have is that i didn't want to use the paint event cuz i will use other functions when i move or resize the tables but if this is the only way i could use a little help on how to use a arraylist or dataset so that my lines would stay and also in place when tables are added or moved.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,605
Location
Norway
Programming Experience
10+
A line is drawn between two points, to make it easier create a Line class/structure with these two properties StartPoint and EndPoint. Use a List(Of Line) to maintain the collection of lines. In Paint you do For Each draw these lines.
VB.NET:
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Structure[/COLOR][/SIZE][SIZE=2] Line[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] StartPoint, EndPoint [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Point[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Structure[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] myLines [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] List([/SIZE][SIZE=2][COLOR=#0000ff]Of[/COLOR][/SIZE][SIZE=2] Line)[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Paint([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.PaintEventArgs) _[/SIZE]
[SIZE=2][COLOR=#0000ff]Handles [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Paint[/SIZE]
[SIZE=2][COLOR=#0000ff]For [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] l [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Line [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] myLines[/SIZE]
[SIZE=2]e.Graphics.DrawLine(Pens.Blue, l.StartPoint, l.EndPoint)[/SIZE]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
Now If you add (or remove) a line to the list collection it will be drawn (or not drawn) by Paint "next time" or by your Refresh/Invalidate request.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
I was thinking to use a dataset so i could have the name of the form and it's location and also the form that has a relattionship with it.
So i guess when i use invalidate the removed rows will not draw.
Ok i'll try and if i have problems i'll post them.
Thanks again.
 

sapator

Member
Joined
Oct 4, 2006
Messages
23
Programming Experience
1-3
Hi.
I'm asking for your help again because i run into some problems.
Ok first i'll post my code and then explain (exuse some Greek comments in the code :) )

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Paint([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.PaintEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Paint
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strTableName [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strRefTableName [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strLocationMain [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] intTable [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] x [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] x = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows.Count - 1
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows(x).Item(0).ToString = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows(x).Item(2).ToString [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Continue[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]For
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' maintables main table column
[/COLOR][/SIZE][SIZE=2]strTableName = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows(x).Item(0).ToString
[/SIZE][SIZE=2][COLOR=#008000]' maintables main table column location
[/COLOR][/SIZE][SIZE=2]strLocationMain = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows(x).Item(1).ToString
locationMain.X = pointconvertor([/SIZE][SIZE=2][COLOR=#800000]"x"[/COLOR][/SIZE][SIZE=2], strLocationMain)
locationMain.Y = pointconvertor([/SIZE][SIZE=2][COLOR=#800000]"y"[/COLOR][/SIZE][SIZE=2], strLocationMain)
[/SIZE][SIZE=2][COLOR=#008000]' referenced maintables column
[/COLOR][/SIZE][SIZE=2]strRefTableName = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows(x).Item(2).ToString
intTable = arrayTablesInForm1.IndexOf(strRefTableName)
[/SIZE][SIZE=2][COLOR=#008000]' Psaxno na do an iparxei mesa stin mainform to table
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' an oxi continue for. An nai tote perno to location tou
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] intTable = -1 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Continue[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]For
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strRefTableLoc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] y [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] y = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows.Count - 1
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows(y).Item(0).ToString = strRefTableName [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]strRefTableLoc = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].DataSet1.Tables(0).Rows(y).Item(1).ToString
locationSecond.X = pointconvertor([/SIZE][SIZE=2][COLOR=#800000]"x"[/COLOR][/SIZE][SIZE=2], strRefTableLoc)
locationSecond.Y = pointconvertor([/SIZE][SIZE=2][COLOR=#800000]"y"[/COLOR][/SIZE][SIZE=2], strRefTableLoc)
[/SIZE][SIZE=2][COLOR=#0000ff]Exit[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]For
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]e.Graphics.DrawLine(Pens.Black, locationMain, locationSecond)
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

Ok. What i do here is, i have a dataset with the first column as the name of the Main table, the second as it's location and the thirt as the name of the table it references. First i check that no main table references itself.
So then i take the table name and i have a function (pointconvertor) that takes it's cordinates (the Locationmain and locationsecond are declared Private somewhere in my code).
Then i try to take the location of the referenced table. The "arrayTablesInForm1" is an array that contain all the tables that are added in the mainform. I look in the array and if the table exists then i take it's coordinates and i exit my inside for.
Then i draw the 2 tables reference line.....

So the problems i have.....
The lines are drawn but some of them are shorter and misplaced. I've checked the Location coordinates and they seem to be right for the tables.
Also if i maximize and then restore the form, the lines become different (i don't move any forms). I must note that because the relationships i get from the tables are from both primary and foreign, some relationships lines are draw again (the same line coordinate above another drawn line).
Any thoughts? :(
 
Top Bottom