none
help convert vb6 to vb.net RRS feed

  • Question

  • i want convert code vb6 to vb..net

    Option Explicit
    
    Dim Curve As clsBezier
    Dim SelectedPoint As Long
    
    Private Sub Render()
        Dim t As Double
        Dim X As Double
        Dim Y As Double
        Dim i As Long
        
        picDisp.Cls
        
        For t = 0 To 1 Step 1 / 1000    '1000 iterations (increase for a smoother curve)
            Curve.GetBezierPoint t, X, Y 'find the positions for the curve
            picDisp.PSet (X, Y), vbRed  'draw curve
        Next
        
        'draw handles
        If chkPoints.Value Then
            For i = 0 To Curve.GetNumVerts - 1
                picDisp.Circle (Curve.GetPointX(i), Curve.GetPointY(i)), 3, vbBlue
            Next
        End If
        
        'draw lines
        If chkLines.Value Then
            For i = 0 To Curve.GetNumVerts - 2
                picDisp.Line (Curve.GetPointX(i), Curve.GetPointY(i))-(Curve.GetPointX(i + 1), Curve.GetPointY(i + 1)), vbBlue
            Next
        End If
        
        picDisp.Refresh
    End Sub
    
    Private Sub chkLines_Click()
        Render
    End Sub
    
    Private Sub chkPoints_Click()
        Render
    End Sub
    
    Private Sub Form_Load()
        Set Curve = New clsBezier
        
        'initiate a curve with 3 points
        Curve.InitCurve 3
        
        'set initial positions for the points
        Curve.SetPointCoords 0, 50, 200
        Curve.SetPointCoords 1, 20, 50
        Curve.SetPointCoords 2, 350, 160
        
        Render
        
        Me.Show
        MsgBox "Drag the handles with the left mouse button" & vbNewLine & "Click with the right mouse button on points to split them", vbOKOnly, "Bezier Curves"
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        'free up memory
        Curve.RemoveCurve
        Set Curve = Nothing
    End Sub
    
    Private Sub picDisp_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button Then
            SelectedPoint = Curve.FindPoint(X, Y, 5) 'find which point we are close to clicking on
            picDisp_MouseMove Button, Shift, X, Y
        End If
    End Sub
    
    Private Sub picDisp_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then
            If SelectedPoint > -1 Then
                Curve.SetPointCoords SelectedPoint, X, Y 'move the selected point
                Render
            End If
        End If
    End Sub
    
    Private Sub picDisp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim tempX() As Double
        Dim tempY() As Double
        Dim i As Long
        Dim numVerts As Long
        
        If Button = 2 Then  'add new vertecies by creating a new line and replacing the old one
            If SelectedPoint > 0 And SelectedPoint < Curve.GetNumVerts - 1 Then
                numVerts = Curve.GetNumVerts
                ReDim tempX(numVerts - 1) 'for storing the old coords
                ReDim tempY(numVerts - 1)
                
                'store old coords
                For i = 0 To numVerts - 1
                    tempX(i) = Curve.GetPointX(i)
                    tempY(i) = Curve.GetPointY(i)
                Next
                
                'we're adding two new points
                numVerts = numVerts + 2
                
                're-initialize the curve, since we're adding points
                Curve.InitCurve numVerts
                
                'set coords for all points before the addition
                For i = 0 To SelectedPoint - 1
                    Curve.SetPointCoords i, tempX(i), tempY(i)
                Next
                
                'calculate and set the new coords
                Curve.SetPointCoords SelectedPoint, (tempX(SelectedPoint) - tempX(SelectedPoint - 1)) / 2 + tempX(SelectedPoint - 1), _
                                                    (tempY(SelectedPoint) - tempY(SelectedPoint - 1)) / 2 + tempY(SelectedPoint - 1)
                
                'this is the same as the one which was clicked on, except it's placement in the array.
                Curve.SetPointCoords SelectedPoint + 1, tempX(SelectedPoint), tempY(SelectedPoint)
                
                Curve.SetPointCoords SelectedPoint + 2, (tempX(SelectedPoint + 1) - tempX(SelectedPoint)) / 2 + tempX(SelectedPoint), _
                                                        (tempY(SelectedPoint + 1) - tempY(SelectedPoint)) / 2 + tempY(SelectedPoint)
                
                'set coords for all points after the addition
                For i = SelectedPoint + 3 To numVerts - 1
                    Curve.SetPointCoords i, tempX(i - 2), tempY(i - 2)
                Next
                
                lblNumPoints.Caption = numVerts
                
                SelectedPoint = -1
                
                Render
            End If
        End If
        
        Erase tempX
        Erase tempY
    End Sub

    Wednesday, November 22, 2017 12:48 AM

All replies

  • i want convert code vb6 to vb..net

    It will be easier to start from scratch.

    The Bezier curve is available with GDI.
    https://msdn.microsoft.com/en-us/library/a7h66bsy(v=vs.110).aspx

    That replaces the drawing routine.   You can start with a simple case where the points are known and fixed.

    Then you need to add code for dragging the handles and getting the new curve points. That needs a mouse down handler, a mouse move handler (for updating intermediate points) and a mouseup handler for the final point.   You will find plenty of examples of how to draw a straight line with the mouse in .Net.  That's what moving the point is, except that you are not drawing the line, but simply getting the end point, because that's where the handle has to move to.  The only bit of code you need to add is to find the handle nearest to the mousedown position.

    Wednesday, November 22, 2017 1:14 AM
  • i want convert code vb6 to vb..net

    It will be easier to start from scratch.

    The Bezier curve is available with GDI.
    https://msdn.microsoft.com/en-us/library/a7h66bsy(v=vs.110).aspx

    That replaces the drawing routine.   You can start with a simple case where the points are known and fixed.

    Then you need to add code for dragging the handles and getting the new curve points. That needs a mouse down handler, a mouse move handler (for updating intermediate points) and a mouseup handler for the final point.   You will find plenty of examples of how to draw a straight line with the mouse in .Net.  That's what moving the point is, except that you are not drawing the line, but simply getting the end point, because that's where the handle has to move to.  The only bit of code you need to add is to find the handle nearest to the mousedown position.

    i want use like this 

    Wednesday, November 22, 2017 1:25 AM
  • i want use like this 

    I have no idea what that means, but it sure doesn't look like Beziers.

    Wednesday, November 22, 2017 1:29 AM
  • i want use like this 

    I have no idea what that means, but it sure doesn't look like Beziers.

    please look https://www.youtube.com/watch?v=qmUI-g3dz7w
    Wednesday, November 22, 2017 2:08 AM
  • please look https://www.youtube.com/watch?v=qmUI-g3dz7w

    Why not just describe what you want to do?   Generally, describing something pretty much tells you how to go about it.  For instance, the link I posted Creates the start, end, and two control points for the curve and Draws the Bézier curve to the screen, which seems pretty close to what you want to do.  Then you only need to add code for moving the points.

    Wednesday, November 22, 2017 2:23 AM
  • Hi

    Here is a simple Bezier curve example with drag-able control points. Maybe you can develop a 3D graphic distortion example to show us here.

    ' https://docs.microsoft.com/en-gb/dotnet/api/?view=netframework-4.7.1&term=Bezier
    
    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim pts() As Point = {New Point(100, 100), New Point(200, 10), New Point(350, 50), New Point(500, 300)}
        Dim dragging As Boolean = False
        Dim dragP As Integer
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    
        End Sub
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    
            Dim blackPen As New Pen(Color.Black, 3)
    
            e.Graphics.DrawBezier(blackPen, pts(0), pts(1), pts(2), pts(3))
    
            For Each pt As Point In pts
                Dim r As New Rectangle(pt.X - 4, pt.Y - 4, 8, 8)
                e.Graphics.DrawEllipse(blackPen, r)
            Next
    
        End Sub
        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
            Dim c As Integer = 0
            For Each pt As Point In pts
                Dim r As New Rectangle(pt.X - 4, pt.Y - 4, 8, 8)
                If r.Contains(e.Location) Then
                    dragP = c
                    dragging = True
                    Exit For
                End If
                c += 1
            Next
        End Sub
        Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
            dragging = False
        End Sub
        Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
            If dragging Then
                pts(dragP) = e.Location
                Invalidate()
            End If
        End Sub
    End Class
    


    Regards Les, Livingston, Scotland

    Wednesday, November 22, 2017 2:30 AM
  • Hi

    Here is a simple Bezier curve example with drag-able control points. Maybe you can develop a 3D graphic distortion example to show us here.

    ' https://docs.microsoft.com/en-gb/dotnet/api/?view=netframework-4.7.1&term=Bezier
    
    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim pts() As Point = {New Point(100, 100), New Point(200, 10), New Point(350, 50), New Point(500, 300)}
        Dim dragging As Boolean = False
        Dim dragP As Integer
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    
        End Sub
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    
            Dim blackPen As New Pen(Color.Black, 3)
    
            e.Graphics.DrawBezier(blackPen, pts(0), pts(1), pts(2), pts(3))
    
            For Each pt As Point In pts
                Dim r As New Rectangle(pt.X - 4, pt.Y - 4, 8, 8)
                e.Graphics.DrawEllipse(blackPen, r)
            Next
    
        End Sub
        Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
            Dim c As Integer = 0
            For Each pt As Point In pts
                Dim r As New Rectangle(pt.X - 4, pt.Y - 4, 8, 8)
                If r.Contains(e.Location) Then
                    dragP = c
                    dragging = True
                    Exit For
                End If
                c += 1
            Next
        End Sub
        Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
            dragging = False
        End Sub
        Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
            If dragging Then
                pts(dragP) = e.Location
                Invalidate()
            End If
        End Sub
    End Class


    Regards Les, Livingston, Scotland

    how use like this

    Wednesday, November 22, 2017 2:48 AM
  • Hi

    Have you,personally, written any code at all?

    Are you just expecting others here to write something that you can just copy/paste?

    That is not what this forum is for.

    *

    There appears to be plenty of information provided to you in this thread - certainly enough for you to make a start with your own code.


    Regards Les, Livingston, Scotland

    Wednesday, November 22, 2017 2:57 AM
  • Hi

    Have you,personally, written any code at all?

    Are you just expecting others here to write something that you can just copy/paste?

    That is not what this forum is for.

    *

    There appears to be plenty of information provided to you in this thread - certainly enough for you to make a start with your own code.


    Regards Les, Livingston, Scotland

    sir gave me an example of two lines

    Wednesday, November 22, 2017 3:35 AM
  • Hi

    Did you try the code already posted in this thread? There are many lines in it.


    Regards Les, Livingston, Scotland

    Wednesday, November 22, 2017 3:53 AM
  • i want convert code vb6 to vb..net


    If you're serious about learning how to convert from VB6 to VB .NET,
    study these resources:

    Visual Basic 6 to .NET Function Equivalents
    https://en.wikibooks.org/wiki/Visual_Basic_.NET/Visual_Basic_6_to_.NET_Function_Equivalents

    Microsoft Visual Basic 6.0 Migration Resource Center
    https://msdn.microsoft.com/en-us/vstudio/ms788233

    - Wayne

    Wednesday, November 22, 2017 6:20 AM
  • Like others, I assume you did never use this code. 

    There is few needed to change, if you copy and past the code in VB15

    In fact only adding the parenthesis with a function (I was curious if this also was automatically done, that is not, I did not remember me that)

    Option Explicit On
    Option Strict Off
    Public Class Form1
        Dim Curve As clsBezier
        Dim SelectedPoint As Long
    
        Private Sub Render()
            Dim t As Double
            Dim X As Double
            Dim Y As Double
            Dim i As Long
    
            picDisp.Cls
    
            For t = 0 To 1 Step 1 / 1000    '1000 iterations (increase for a smoother curve)
                Curve.GetBezierPoint(t, X, Y) 'find the positions for the curve
                picDisp.PSet(X, Y), vbRed  'draw curve
        Next
    
            'draw handles
            If chkPoints.Value Then
                For i = 0 To Curve.GetNumVerts - 1
                    picDisp.Circle(Curve.GetPointX(i), Curve.GetPointY(i)), 3, vbBlue
            Next
            End If
    
            'draw lines
            If chkLines.Value Then
                For i = 0 To Curve.GetNumVerts - 2
                    picDisp.Line(Curve.GetPointX(i), Curve.GetPointY(i))-(Curve.GetPointX(i + 1), Curve.GetPointY(i + 1)), vbBlue
            Next
            End If
    
            picDisp.Refresh
        End Sub
    
        Private Sub chkLines_Click()
            Render()
        End Sub
    
        Private Sub chkPoints_Click()
            Render()
        End Sub
    
        Private Sub Form_Load()
            Curve = New clsBezier
    
            'initiate a curve with 3 points
            Curve.InitCurve 3
    
        'set initial positions for the points
            Curve.SetPointCoords(0, 50, 200)
            Curve.SetPointCoords(1, 20, 50)
            Curve.SetPointCoords(2, 350, 160)
    
            Render()
    
            Me.Show()
            MsgBox "Drag the handles with the left mouse button" & vbNewLine & "Click with the right mouse button on points to split them", vbOKOnly, "Bezier Curves"
    End Sub
    
        Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
            'free up memory
            Curve.RemoveCurve
        Set Curve = Nothing
    End Sub
    
        Private Sub picDisp_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
            If Button Then
                SelectedPoint = Curve.FindPoint(X, Y, 5) 'find which point we are close to clicking on
                picDisp_MouseMove(Button, Shift, X, Y)
            End If
        End Sub
    
        Private Sub picDisp_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
            If Button = 1 Then
                If SelectedPoint > -1 Then
                    Curve.SetPointCoords(SelectedPoint, X, Y) 'move the selected point
                    Render()
                End If
            End If
        End Sub
    
        Private Sub picDisp_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
            Dim tempX() As Double
            Dim tempY() As Double
            Dim i As Long
            Dim numVerts As Long
    
            If Button = 2 Then  'add new vertecies by creating a new line and replacing the old one
                If SelectedPoint > 0 And SelectedPoint < Curve.GetNumVerts - 1 Then
                    numVerts = Curve.GetNumVerts
                    ReDim tempX(numVerts - 1) 'for storing the old coords
                    ReDim tempY(numVerts - 1)
    
                    'store old coords
                    For i = 0 To numVerts - 1
                        tempX(i) = Curve.GetPointX(i)
                        tempY(i) = Curve.GetPointY(i)
                    Next
    
                    'we're adding two new points
                    numVerts = numVerts + 2
    
                    're-initialize the curve, since we're adding points
                    Curve.InitCurve(numVerts)
    
                    'set coords for all points before the addition
                    For i = 0 To SelectedPoint - 1
                        Curve.SetPointCoords(i, tempX(i), tempY(i))
                    Next
    
                    'calculate and set the new coords
                    Curve.SetPointCoords) SelectedPoint, (tempX(SelectedPoint) - tempX(SelectedPoint - 1)) / 2 + tempX(SelectedPoint - 1),tempY(SelectedPoint) - tempY(SelectedPoint - 1)) / 2 + tempY(SelectedPoint - 1))
    
                'this is the same as the one which was clicked on, except it's placement in the array.
                    Curve.SetPointCoords(SelectedPoint + 1, tempX(SelectedPoint), tempY(SelectedPoint))
    
                    Curve.SetPointCoords(SelectedPoint + 2, (tempX(SelectedPoint + 1) - tempX(SelectedPoint)) / 2 + tempX(SelectedPoint),
                                                        tempY(SelectedPoint + 1) - tempY(SelectedPoint)) / 2 + tempY(SelectedPoint))
    
                'set coords for all points after the addition
                    For i = SelectedPoint + 3 To numVerts - 1
                        Curve.SetPointCoords(i, tempX(i - 2), tempY(i - 2))
                    Next
    
                    lblNumPoints.Caption = numVerts
    
                    SelectedPoint = -1
    
                    Render()
                End If
            End If
    
            Erase tempX
            Erase tempY
        End Sub
    End Class

    Be aware that the clsBezier is not suplied by you and probably can this be done with VB15 better than ever done with VB6.


    Success
    Cor

    Wednesday, November 22, 2017 7:36 AM
  • Be aware that the clsBezier is not suplied by you and probably can this be done with VB15 better than ever done with VB6.

    This might be the base class, but definitely not worth the trouble of converting.
    https://github.com/DeepSOIC/SplineTravel/blob/master/clsBezier.cls

    Wednesday, November 22, 2017 9:17 AM