I was trying to create an application implementing the Douglas Peucker algorithm in VB.NET. I already finished coding the program and tried to compile it but when I try to draw on the form, it is not working. My source code is below, I just want to ask if there are some missing code or are there any code I have to include, or there are "WRONG" codes I've included. Thank you for your help!

If you need the other class, kindly inform me, I will just attach it. Thanks

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms


Namespace RamerDouglasPeucker2

    Partial Public Class Form1
        Inherits Form

        Private _calculateDouglasPeuckerReduction As [Boolean] = False
        Private _amerenPoints As New List(Of RamerDouglasPeucker2.Point)()

        Public Sub New()
            InitializeComponent()
        End Sub

        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

            Dim drawingPoints As New List(Of System.Drawing.Point)()


            For Each point As RamerDouglasPeucker2.Point In _amerenPoints
                drawingPoints.Add(New System.Drawing.Point(Convert.ToInt32(point.X), Convert.ToInt32(point.Y)))

            Next

            If drawingPoints.Count > 2 Then
                e.Graphics.DrawLines(New Pen(Brushes.Black, 2), drawingPoints.ToArray())
                lblOriginal.Text = drawingPoints.Count.ToString()

                If _calculateDouglasPeuckerReduction Then
                    Dim points As List(Of RamerDouglasPeucker2.Point) = Utility.DouglasPeuckerReduction(_amerenPoints, Convert.ToDouble(TolerancePts.Value))

                    drawingPoints = New List(Of System.Drawing.Point)()
                    For Each point As RamerDouglasPeucker2.Point In points
                        drawingPoints.Add(New System.Drawing.Point(Convert.ToInt32(point.X), Convert.ToInt32(point.Y)))
                    Next

                    e.Graphics.DrawLines(New Pen(Brushes.Red, 2), drawingPoints.ToArray())
                    lblSimplified.Text = drawingPoints.Count.ToString()
                End If
            End If

            MyBase.OnPaint(e)

        End Sub

        Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
            If e.Button = MouseButtons.Left Then
                _amerenPoints.Add(New RamerDouglasPeucker2.Point(e.X, e.Y))
                Me.Invalidate()
            End If
        End Sub

        Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
            'DO the calculation
            _calculateDouglasPeuckerReduction = True
            Me.Invalidate()
        End Sub

        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
            If e.Button = MouseButtons.Left Then
                _amerenPoints.Clear()
                _calculateDouglasPeuckerReduction = False
            End If
        End Sub

        Private Sub Tolerance_ValueChanged(ByVal sender As Object, ByVal e As EventArgs)
            Me.Invalidate()
        End Sub

        Private Sub InitializeComponent()
            Me.OrgPoints = New System.Windows.Forms.Label
            Me.PtsSimplified = New System.Windows.Forms.Label
            Me.lbTolerance = New System.Windows.Forms.Label
            Me.Tolerance = New System.Windows.Forms.NumericUpDown
            CType(Me.Tolerance, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'OrgPoints
            '
            Me.OrgPoints.AutoSize = True
            Me.OrgPoints.Location = New System.Drawing.Point(12, 9)
            Me.OrgPoints.Name = "OrgPoints"
            Me.OrgPoints.Size = New System.Drawing.Size(126, 13)
            Me.OrgPoints.TabIndex = 0
            Me.OrgPoints.Text = "Number of Original Points"
            '
            'PtsSimplified
            '
            Me.PtsSimplified.AutoSize = True
            Me.PtsSimplified.Location = New System.Drawing.Point(210, 9)
            Me.PtsSimplified.Name = "PtsSimplified"
            Me.PtsSimplified.Size = New System.Drawing.Size(164, 13)
            Me.PtsSimplified.TabIndex = 1
            Me.PtsSimplified.Text = "Number of Points after Simplifying"
            '
            'lbTolerance
            '
            Me.lbTolerance.AutoSize = True
            Me.lbTolerance.Location = New System.Drawing.Point(497, 9)
            Me.lbTolerance.Name = "lbTolerance"
            Me.lbTolerance.Size = New System.Drawing.Size(55, 13)
            Me.lbTolerance.TabIndex = 2
            Me.lbTolerance.Text = "Tolerance"
            '
            'Tolerance
            '
            Me.Tolerance.DecimalPlaces = 2
            Me.Tolerance.Increment = New Decimal(New Integer() {25, 0, 0, 131072})
            Me.Tolerance.Location = New System.Drawing.Point(570, 7)
            Me.Tolerance.Name = "Tolerance"
            Me.Tolerance.Size = New System.Drawing.Size(68, 20)
            Me.Tolerance.TabIndex = 10
            Me.Tolerance.Value = New Decimal(New Integer() {5, 0, 0, 0})
            '
            'Form1
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(650, 418)
            Me.Controls.Add(Me.Tolerance)
            Me.Controls.Add(Me.lbTolerance)
            Me.Controls.Add(Me.PtsSimplified)
            Me.Controls.Add(Me.OrgPoints)
            Me.Name = "Form1"
            CType(Me.Tolerance, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()

        End Sub
        Friend WithEvents lblOriginal As System.Windows.Forms.Label
        Friend WithEvents lblSimplified As System.Windows.Forms.Label
        Friend WithEvents lblTolerance As System.Windows.Forms.Label
        Private WithEvents TolerancePts As System.Windows.Forms.NumericUpDown
        Friend WithEvents OrgPoints As System.Windows.Forms.Label
        Friend WithEvents PtsSimplified As System.Windows.Forms.Label
        Friend WithEvents lbTolerance As System.Windows.Forms.Label
        Private WithEvents Tolerance As System.Windows.Forms.NumericUpDown



        Protected Overrides Sub Finalize()
            MyBase.Finalize()
        End Sub
    End Class
End Namespace

Well, for a start, what do you mean by 'not working'? Do you get an error message, is some functionality OK but not all of it or does it simply do nothing at all?

Thank you. It is not working I mean I can't get the right output. When I compile the program I got no errors but when I tried to draw on the form, there's no output. It means, the drawing method is not working.

Put break point in your onPaint method and run in debug, just to make sure the method is being called correctly.

Put break point in your onPaint method and run in debug, just to make sure the method is being called correctly.

I tried it but i got an error. "Point is a type and cannot be used as an expression"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.