1

I have the following Sub function I need to convert from Vb6 to Vb.net.

The .Scale() & .Line() methods aren't supported anymore and I am brand new to the VB language so I am having a hard time doing so.

Public Sub DrawMap(picMap As PictureBox, ByVal x1%, ByVal x2%, ByVal y1%, ByVal y2%)
    Dim i&, temp, lColor As Long
    
    picMap.Scale (x1 - 5, y2 + 5)-(x2 + 5, y1 - 5)
    
    frmMain.picFirst.Scale (x1st - 4, y1st + 4)-(x1st + 4, y1st - 4)
    
    
    
    For i = LBound(arrDrawDie) To UBound(arrDrawDie)
      temp = Split(CStr(arrDrawDie(i)), gDelim)
      If temp(UBound(temp)) = 0 Then lColor = &HC0FFC0 Else If temp(UBound(temp)) = -2 Then lColor = &H8000000A Else lColor = &H8080FF
    
      picMap.Line (temp(0) - 0.4, temp(1) - 0.4)-(temp(0) + 0.4, temp(1) + 0.4), lColor, BF
      If temp(0) > x1st - 4 And temp(1) > y1st - 4 And temp(0) < x1st + 4 And temp(1) < y1st + 4 Then
        
        
        frmMain.picFirst.Line (temp(0) - 0.4, temp(1) - 0.4)-(temp(0) + 0.4, temp(1) + 0.4), &HC0FFC0, BF
      End If
    Next i
    
    picMap.Picture = picMap.Image
    
    
    
    picMap.Line (x1st - 0.4, y1st - 0.4)-(x1st + 0.4, y1st + 0.4), vbBlue, BF
    frmMain.picFirst.Line (x1st - 0.4, y1st - 0.4)-(x1st + 0.4, y1st + 0.4), vbBlue, BF
    
    frmMain.lblFirst.Caption = "X: " + Format(x1st, "000") + "  Y: " + Format(y1st, "000")
    
    
End Sub

What tools or methods can I use in vb.net to get similar or exact results like in the vb6 code.

Nikita
  • 682
  • 2
  • 13
trankilo
  • 11
  • 2
  • 2
    Handle the `Paint()` event of the PictureBox, which gives you an `e.Graphics` parameter. The [Graphics](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics?view=windowsdesktop-7.0) surface can be TRANSFORMED ([Translate](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.translatetransform?view=windowsdesktop-7.0), [Scale](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.scaletransform?view=windowsdesktop-7.0), [Rotate](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.rotatetransform?view=windowsdesktop-7.0)). – Idle_Mind Mar 01 '23 at 21:04
  • 1
    Note that in VB6, drawing with `Line()` was PERSISTENT on top of the PB, whereas drawing on top of a VB.Net PB in the `Paint()` event is NOT. You have to maintain a sequence/list of draws and re-paint them every time in the Paint() event. The way around this is to draw to a BITMAP instead and display that in the PB. In either case, you'd use methods like [Graphics.DrawLine()](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics.drawline?view=windowsdesktop-7.0). The VB.Net version is going to be VERY DIFFERENT than what you were doing in VB6...no way around that. – Idle_Mind Mar 01 '23 at 21:08
  • Here is an example for .Line https://social.msdn.microsoft.com/Forums/vstudio/en-US/39e307ed-383e-40c3-b980-5741fdf53e74/how-to-draw-line-on-picturebox-in-net-when-i-pass-picturebox-as-parameter-to-some-function?forum=vbgeneral – Nikita Mar 01 '23 at 21:10
  • In the example above, please be sure to `Dispose()` of the previous Bitmap in the PB. You also need to `Dispose()` any Pens and Graphics that YOU create. – Idle_Mind Mar 01 '23 at 21:19
  • First thing I would do is replace the type characters: https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/type-characters – jmoreno Mar 08 '23 at 02:20

0 Answers0