picturebox.Scale, picturebox.Line in vb.net

trankilo 0 Reputation points
2023-03-01T20:37:24.1833333+00:00

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.

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


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
Developer technologies | Windows Forms
Developer technologies | .NET | Other
Developer technologies | VB
{count} votes

1 answer

Sort by: Most helpful
  1. LesHay 7,141 Reputation points
    2023-03-01T21:31:29.24+00:00

    Hi

    Here is the most simple example to get started with.

    If you want to try this, start a new test project, in the Designer, add Button1 for x scale plus, Button2 for xscale minus, Button3 for yscale plus, Button4 for yscale minus and a couple of labels just to show what the buttons are for. The copy/replace all code in Form1 with the code below. NOTE: if you want to draw in a container e.g. PictureBox etc, then you would use the Paint event for that container instead of the one I show below (which is for the Form itself)

    111

    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim xScale As Single = 1
      Dim yScale As Single = 1
      Dim th As Single = 2
      Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
    
        e.Graphics.ScaleTransform(xScale, yScale)
    
        e.Graphics.DrawRectangle(New Pen(Color.Blue, th), New Rectangle(50, 20, 80, 120))
    
        e.Graphics.DrawLine(New Pen(Color.Red, th + 2), 10, 40, 200, 120)
      End Sub
    
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        xScale += 0.2D
        Invalidate()
      End Sub
      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        xScale -= 0.2D
        If xScale < 0.5 Then xScale = 0.4
        Invalidate()
      End Sub
      Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        yScale += 0.2D
        Invalidate()
      End Sub
      Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        yScale -= 0.2D
        If yScale < 0.5 Then yScale = 0.4
        Invalidate()
      End Sub
    End Class
    
    
    2 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.