PDA

View Full Version : Drawing in VB2005


sphenisc
9th July 2008, 08:44 AM
I have a program in VB6 containing the following Sub. I need to convert to VB2005, including the Line and PSet methods. Any ideas on how to do this? I've looked at EventHandlers, e As System.Windows.Forms.PaintEventArgs, Pictureboxes etc,etc. and have no idea what to choose, how to implement it, or generally what 90% of it means.

[I'm not a programmer, I just pretend to be one at work occasionally.]

Sub displaygrid(nx As Integer, ny As Integer, t As Integer)
FillStyle = 0: ScalingFx = 200: ScalingFy = 150
For mcol = 0 To nx
For mrow = 0 To ny
plotc = mcol * ScalingFx + 500
plotr = (ny - mrow) * ScalingFy + 500

Form1.Line (plotc, plotr)-Step(ScalingFx, ScalingFy), , B
If Obstacles(mcol, mrow) = True Then Form1.Line (plotc, plotr)-Step(ScalingFx, ScalingFy), vbBlue, BF
For i = 4 To 9
If Attractant(mcol, mrow, i) > 0 Then Form1.Line (plotc, plotr)-Step(ScalingFx, ScalingFy), RGB(0, 17 * Attractant(mcol, mrow, i) Mod 255, 0), BF
If DestinationsbyDesire(mcol, mrow, i) Then Form1.Line (plotc, plotr)-Step(ScalingFx, ScalingFy), vbMagenta, BF
Next
CellAgCounter = 1
Do While LkUpAgent(mcol, mrow, CellAgCounter) > 0
Patmc = (CellAgCounter * 2) Mod (ScalingFx - 2) + 1
Patmr = Int((CellAgCounter * 2) / (ScalingFx - 2)) * 5 + 10
Patplotc = plotc + Patmc
Patplotr = plotr + Patmr
PSet (Patplotc, Patplotr), RGB(300, 50, 6)
CellAgCounter = CellAgCounter + 1
Loop
For i = 4 To 9
If DestinationsbyDesire(mcol, mrow, i) Then Form1.Line (plotc, plotr)-Step(ScalingFx, ScalingFy), vbMagenta, BF
Next

Next
Next
Label1.Caption = "Cyc " & t
Label1.Refresh
End Sub

Wowbagger
9th July 2008, 10:42 AM
You want to look into GDI+, which has functions for drawing lines and setting pixels.
It's not my strongest area of knowledge, but here is what I can offer off the top of my head:

System.Drawing.Graphics.DrawLine is commonly used to draw lines.

System.Drawing.Bitmap.SetPixel is the closest equivalent to PSet, that I know of. So, you might have to render the lines, and save it as a Bitmap (in memory, not necessarily to disk), first. Then set the pixels.

When I have time, I might be able to convert that code for you.