none
how mouse line bezier curves in desktop vb.net RRS feed

  • Question

  • mouse line bezier curves in desktop not form vb.net

    Imports System.Drawing.Drawing2D
    
    Public Class Form1
        Inherits Form
    
    
    
        ' The points selected by the user.
        Private Points As New List(Of Point)()
    
        ' Select a point.
        Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseClick
            Points.Add(e.Location)
            Refresh()
        End Sub
    
        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Me.Paint
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
    
            ' Draw the points.
            For Each point As Point In Points
                e.Graphics.FillEllipse(Brushes.Black, point.X - 3, point.Y - 3, 5, 5)
            Next point
            If Points.Count < 2 Then
                Return
            End If
    
            ' Draw the curve.
            e.Graphics.DrawCurve(Pens.Red, Points.ToArray())
        End Sub
    
     
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Points = New List(Of Point)()
            Refresh()
        End Sub
    End Class

    like this 

    Friday, January 26, 2018 8:01 PM

Answers

  • pro,

    "you test bro not work"

    You need to define exactly what working is.

    Use Leshay's code from his post above and add the transparent form code in the form load event.

    The code you are posting does nothing.

    PS This is what you will get with Leshay's example and transparent backcolor.


    Friday, January 26, 2018 11:10 PM

All replies

  • Hi

    Here is one example of drawing a Bezier Curve (with drag points)

    ' Blank Form1
    
    ' DrawBezier, Bezier Curve with drag points
    ' 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
            DoubleBuffered = True
        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

    • Proposed as answer by tommytwotrain Friday, January 26, 2018 11:59 PM
    Friday, January 26, 2018 9:26 PM
  • Hi

    Here is one example of drawing a Bezier Curve (with drag points)

    ' Blank Form1
    
    ' DrawBezier, Bezier Curve with drag points
    ' 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
            DoubleBuffered = True
        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

    This is not required
    Friday, January 26, 2018 9:37 PM

  • This is not required

    and thank you too!

    It answers the question you posted

    how mouse line bezier curves in desktop vb.net


    Regards Les, Livingston, Scotland

    Friday, January 26, 2018 10:00 PM

  • This is not required

    and thank you too!

    It answers the question you posted

    how mouse line bezier curves in desktop vb.net


    Regards Les, Livingston, Scotland

    bezier curves mouse handling hwd 


    Friday, January 26, 2018 10:04 PM
  • You should finish one question before posting another with the same question.


    https://social.msdn.microsoft.com/Forums/vstudio/en-US/6bd638cb-3349-4ab2-80c8-f204a805894a/how-make-moues-ruler-curve-desktop-background-api-vbnet?forum=vbgeneral


    It is just not clear what you want to do.

    You cant easily draw on the windows desktop if that is what you mean. You can make a transparent form and draw on that such that it covers the desktop.

    In the example the red rectangle is drawn over the desktop using a transparent form.

    Public Class Form7
    
        Private Sub Form7_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    
            e.Graphics.DrawRectangle(New Pen(Color.Red, 4), 20, 20, 200, 200)
    
        End Sub
    
        Private Sub Form7_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.BackColor = Color.Lime
            Me.TransparencyKey = Me.BackColor
    
        End Sub
    End Class

    Friday, January 26, 2018 10:26 PM
  • You should finish one question before posting another with the same question.


    https://social.msdn.microsoft.com/Forums/vstudio/en-US/6bd638cb-3349-4ab2-80c8-f204a805894a/how-make-moues-ruler-curve-desktop-background-api-vbnet?forum=vbgeneral


    It is just not clear what you want to do.

    You cant easily draw on the windows desktop if that is what you mean. You can make a transparent form and draw on that such that it covers the desktop.

    In the example the red rectangle is drawn over the desktop using a transparent form.

    Public Class Form7
    
        Private Sub Form7_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    
            e.Graphics.DrawRectangle(New Pen(Color.Red, 4), 20, 20, 200, 200)
    
        End Sub
    
        Private Sub Form7_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.BackColor = Color.Lime
            Me.TransparencyKey = Me.BackColor
    
        End Sub
    End Class

     code you good but i want use code  live code you not live 

       Private Points As New List(Of Point)()
    
        ' Select a point.
        Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseClick
            Points.Add(e.Location)
            Refresh()
        End Sub
    
        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Me.Paint
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
    
            ' Draw the points.
            For Each point As Point In Points
                e.Graphics.FillEllipse(Brushes.Black, point.X - 3, point.Y - 3, 5, 5)
            Next point
            If Points.Count < 2 Then
                Return
            End If
    
            ' Draw the curve.
            e.Graphics.DrawCurve(Pens.Red, Points.ToArray())
        End Sub

    Friday, January 26, 2018 10:43 PM
  •  code you good but i want use code  live code you not live 

       

    Try using Leshay's code with the transparent form example.

    Do you know how to do the drawing you want or not? The mouse drawing is one thing, making it on the desktop is another.


    Friday, January 26, 2018 10:47 PM
  •  code you good but i want use code  live code you not live 

       

    Try using Leshay's code with the transparent form example.

    Do you know how to do the drawing you want or not? The mouse drawing is one thing, making it on the desktop is another.


    you test bro not work

    Imports System.Drawing.Drawing2D
    
    Public Class Form1
    
    
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.BackColor = Color.Lime
            Me.TransparencyKey = Me.BackColor
    
        End Sub
    
        Private Points As New List(Of Point)()
    
        ' Select a point.
        Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseClick
            Points.Add(e.Location)
            Refresh()
        End Sub
    
        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Me.Paint
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
    
            ' Draw the points.
            For Each point As Point In Points
                e.Graphics.FillEllipse(Brushes.Black, point.X - 3, point.Y - 3, 5, 5)
            Next point
            If Points.Count < 2 Then
                Return
            End If
    
            ' Draw the curve.
            e.Graphics.DrawCurve(Pens.Red, Points.ToArray())
        End Sub
    
    End Class

    Friday, January 26, 2018 10:59 PM
  • pro,

    "you test bro not work"

    You need to define exactly what working is.

    Use Leshay's code from his post above and add the transparent form code in the form load event.

    The code you are posting does nothing.

    PS This is what you will get with Leshay's example and transparent backcolor.


    Friday, January 26, 2018 11:10 PM
  • pro,

    "you test bro not work"

    You need to define exactly what working is.

    Use Leshay's code from his post above and add the transparent form code in the form load event.

    The code you are posting does nothing.

    PS This is what you will get with Leshay's example and transparent backcolor.


    i want use code in form paint

     e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
    
            ' Draw the points.
            For Each point As Point In Points
                e.Graphics.FillEllipse(Brushes.Black, point.X - 3, point.Y - 3, 5, 5)
            Next point
            If Points.Count < 2 Then
                Return
            End If
    
            ' Draw the curve.
            e.Graphics.DrawCurve(Pens.Red, Points.ToArray())

    Friday, January 26, 2018 11:43 PM


  • i want use code in form paint

     e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
    
            ' Draw the points.
            For Each point As Point In Points
                e.Graphics.FillEllipse(Brushes.Black, point.X - 3, point.Y - 3, 5, 5)
            Next point
            If Points.Count < 2 Then
                Return
            End If
    
            ' Draw the curve.
            e.Graphics.DrawCurve(Pens.Red, Points.ToArray())

    Pro,

    You should also mark Leshay's post as the answer to help other viewers.

    Just remove the paint code that is there, and insert the code you want to use.

    You need to learn how it works so you can make it exactly the way you want.

    Friday, January 26, 2018 11:59 PM