Redrawing Function

owinterton

Member
Joined
Mar 18, 2003
Messages
12
Location
California
Im having a problem redrawing the data that I want to show in a form. I am trying to draw on a form that is bigger than normal so it has a scroll bar to expand the window. On that window Im trying to draw lines (much like a line chart). The lines are being plotted from information from my database. I take the information from the database and create coordinates to plot the data. However, when I scroll left or right, the lines that Ive already drawn disappear completely never to be seen again. In VB6 it has the autoRedraw function but Ive found out that no longer applies. Ive read up on how to draw static points using the paint method. But, how do I redraw the data when Im creating dynamic plotting points?
 
If you put your drawing code in the Paint event of your form, you can
use the Invalidate method of your form to force a repaint.
 
Do you have any snipits of code syntax that you could show me because I dont know how to use the invalidate method. Sorry, Im a bit new to .NET. Thanks.
 
You can just use

Code:
Me.Invalidate()

And any code in the Paint event will be called.
 
Ok, that works brilliantly Thanks so much. However, now I have another dilemma. Everytime I scroll (I set the scrolling property on the form to true) the picture repaints itself in the position it thinks it should be in (which is probably due to the way I have my coordinates set up) instead of staying where I want it to be off of the visible screen. How can I keep the lines that I want drawn in the same place and then once I scroll back to it, have it redraw itself? The form that I am creating dynamically is bigger than my screen so I have to have a scroll to make it visible to the user. Would my code be helpful because I feel like Im probably confusing everyone.
 
I dont quite understand your dilemma, but you cant just make the
drawing scroll automatically. You need to make your painting sub
draw the image in the same place all the time (0,0 I would assume),
but only draw a portion of it based on the position of the scrollbars.
 
I kind of figured that I was being confusing. I appreciate you all for tolerating my ignorance.

My goal is to create a string line program to graph where Trains go based on station times (X coordinate) and Train Stations (Y coordinate). So Im developing it on a screen that is 1024 x 768. The form that I am creating, is dynamically created based on our database which stores all of the train stations (Y) and all of the station times which each train stops at (X). For Testing Purposes Im using a 2 dimensional array to simulate the data that needs to be stored. From there Im translating the arrival times of the trains into points based on how the coinciding labels of times as well as train stations. Because I have so many times (24 hour clock each spaced 60 pixels apart) the screen is larger than 1024x768 so it needs a scroll bar. When I draw the line, it works perfectly (thanks to those above for the info). However, when I scroll right, the line redraws itself twice or multiple times depending on how far I scroll. What I want to accomplish is to draw the line so that it coincides with its corresponding time, but when I scroll for it to dissappear so that I can see the other times and other lines. When I scroll back to it, I would like to see it back in its original place.

Currently the line that Ive drawn keeps drawing across the screen so I get a flag-like picture, which disappears when I scroll back to it. What do you suggest would be the best way because Ive never had to do graphics like this before?
 
Me.invalidate causes flicker

We have almost the exact same problem, however when we use Me.Invalidate() in the Paint function, it calls it over and over again like its in a loop. The result is that the graph flickers and slows the computer down to a crawl.

Is there any way to stop this while still having a graph that doesnt get overwritten by other objects, or is there simple code somewhere that will create a line graph based on simple numbers?

Ive seen suggestions to use DirectX, but that just seems like overkill. All we want to do is graph! Thanks
 
So I finally figured out how to make it all work. I created my code to draw the lines and the points in a Picturebox1.Paint() event. In the form load I set the background of the picturebox to "white" thus making the picturebox have to re-paint itself, which then calls my code and makes the lines that I want while keeping it on the screen during scrolling.

The next problem that I have is now that I need to find out where lines intersect each other. I was trying to use the Point-Slope method to find the slope of the line and then generate an equation from that to determine where the intersection point of the two lines occurred. That has gone horribly afoul since I cant figure out why I keep getting different equations everytime. Can anyone tell me a faster, better way of figuring out how to come up with an intersection point for the two lines?
 
Back
Top