[RESOLVED] VB6 - Check if a line (graphic) exists
I'm writting a code to create a grid inside the picturebox http://dret.net/lectures/web-spring09/img/grid.png
I want to check if a line has been already drawn.
I create a line called Line1(0). Then the program executes the funcion .
When I resize the form I call again to the function to add lines in the picturebox.
If I charge the line1(2) twice the programs shows the next error: "The object has been already charged".
I want to know 2 things:
A) How the program can knows if a line exists to prevent to charge it again
B) What I've to write to remove a line from the picturebox. If Load Line1(X) is to create, what is the opposite function that removes a specific line?
Re: VB6 - Check if a line (graphic) exists
Quote:
I want to know 2 things:
A) How the program can knows if a line exists to prevent to charge it again
B) What I've to write to remove a line from the picturebox. If Load Line1(X) is to create, what is the opposite function that removes a specific line?
A) You need to keep track of those objects that you've drawn. Line in this case.
B) It depends: You can redraw the picturebox without the line (either directly or from a back buffer), or
redraw the line ontop of itself with the background color. or
XOR the line.
If you opt for redrawing the line with the background color you will holes in any other objects if the line was drawn on-top of those objects. XORing the line will also create holes.
Re: VB6 - Check if a line (graphic) exists
Use LineName.Count property to know if that line is already loaded or not, for example if Line1.count = 2 then Line1(0) and Line1(1) are already loaded, if you need a 3rd line you'll have to Load Line1(2). Implementation depends on your code.
Load line1(line1.Count-1) will load the next line after the last one loaded.
Re: VB6 - Check if a line (graphic) exists
When I resize the form I call again to the function Load Line1(x)
Is this because if the Form get bigger you want to add more lines?
Then by same token if the Form get smaller would you want to remove lines?
If Load Line1(X) is to create, what is the opposite function that removes a specific line?
Unload Line1(x). I think un means to undo, don't you?:)