none
how make moues ruler curve desktop background api vb.net RRS feed

All replies

  • Uh...What ?  You will need to explain what a "moues ruler curve  desktop background api" is.

    If you say it can`t be done then i`ll try it

    Tuesday, November 21, 2017 1:05 AM
  • Public Class Form1
        ' Drawing parameters.
        Private m_GridX As Integer = 10
        Private m_GridY As Integer = 10
        Private m_PageWid As Integer = 400
        Private m_PageHgt As Integer = 300
        Private m_ShadowThickness As Integer = 20
    
        ' Pens.
        Private m_PenOldLine As Pen = Pens.Black
        Private m_PenNewLine As Pen = Pens.Red
        Private m_PenGrid As Pen = Pens.Black
        Private m_PenRulerNormal As Pen = Pens.Blue
        Private m_PenRulerDrawing As Pen = m_PenNewLine
    
        ' Options.
        Private m_ShowGrid As Boolean = False
        Private m_SnapToGrid As Boolean = False
    
        ' For drawing a new line.
        Private m_Drawing As Boolean = False
        Private m_X1 As Single
        Private m_Y1 As Single
        Private m_X2 As Single
        Private m_Y2 As Single
    
        ' For showing position on the rulers.
        Private m_MouseX As Integer = -10
        Private m_MouseY As Integer = -10
    
        ' Existing lines.
        Private m_Points1() As PointF = {}
        Private m_Points2() As PointF = {}
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            m_ShowGrid = mnuOptionsShowGrid.Checked
            m_SnapToGrid = mnuOptionsSnapToGrid.Checked
    
            ' Arrange the controls.
            Dim wid As Integer = Me.ClientSize.Width - picLeftRuler.Left - picLeftRuler.Width - 3
            Dim hgt As Integer = Me.ClientSize.Height - picTopRuler.Top - picTopRuler.Height - 3
    
            picLeftRuler.Size = New Size(picLeftRuler.Width, hgt)
            picTopRuler.Size = New Size(wid, picTopRuler.Height)
            picCanvas.Size = New Size(wid, hgt)
    
            picLeftRuler.Location = New Point(picLeftRuler.Left, picTopRuler.Top + picTopRuler.Height + 2)
            picTopRuler.Location = New Point(picLeftRuler.Left + picLeftRuler.Width + 2, picTopRuler.Top)
            picCanvas.Location = New Point(picTopRuler.Left, picLeftRuler.Top)
        End Sub
    
        Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
            Me.Close()
        End Sub
    
        Private Sub mnuOptionsShowGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOptionsShowGrid.Click
            m_ShowGrid = Not m_ShowGrid
            mnuOptionsShowGrid.Checked = m_ShowGrid
    
            ' Redraw.
            picCanvas.Invalidate()
        End Sub
    
        Private Sub mnuOptionsSnapToGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOptionsSnapToGrid.Click
            m_SnapToGrid = Not m_SnapToGrid
            mnuOptionsSnapToGrid.Checked = m_SnapToGrid
        End Sub
    
        ' Start drawing a line.
        Private Sub picCanvas_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseDown
            ' Only on left mouse down.
            If e.Button <> Windows.Forms.MouseButtons.Left Then Exit Sub
            m_Drawing = True
    
            ' Start drawing.
            m_X1 = e.X
            m_Y1 = e.Y
            SnapToGrid(m_X1, m_Y1)
            m_X2 = m_X1
            m_Y2 = m_Y1
    
            picCanvas.Invalidate()
            ShowMousePosition(m_X2, m_Y2)
        End Sub
    
        ' Continue drawing.
        Private Sub picCanvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseMove
            m_X2 = e.X
            m_Y2 = e.Y
            SnapToGrid(m_X2, m_Y2)
    
            ' Show the mouse position on the rulers.
            ShowMousePosition(m_X2, m_Y2)
    
            ' Redraw.
            If m_Drawing Then picCanvas.Invalidate()
        End Sub
    
        ' Finish drawing.
        Private Sub picCanvas_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseUp
            If Not m_Drawing Then Exit Sub
            m_Drawing = False
    
            ' Show the mouse position in the non-drawing color.
            ShowMousePosition(m_X2, m_Y2)
    
            ' Save the new line.
            Dim new_index As Integer = m_Points1.Length
            ReDim Preserve m_Points1(new_index)
            ReDim Preserve m_Points2(new_index)
            m_Points1(new_index) = New PointF(m_X1, m_Y1)
            m_Points2(new_index) = New PointF(m_X2, m_Y2)
    
            picCanvas.Invalidate()
        End Sub
    
        ' Snap the point to the nearest grid location.
        Private Sub SnapToGrid(ByRef X As Integer, ByRef Y As Integer)
            ' If grid snap is off, do nothing.
            If Not m_SnapToGrid Then Exit Sub
    
            Dim ix As Integer = CInt(X / m_GridX)
            Dim iy As Integer = CInt(Y / m_GridY)
            X = ix * m_GridX
            Y = iy * m_GridY
        End Sub
    
        ' Draw the lines.
        Private Sub picCanvas_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picCanvas.Paint
            e.Graphics.Clear(picCanvas.BackColor)
    
            ' Draw the grid.
            If m_ShowGrid Then
                For x As Integer = 0 To picCanvas.ClientSize.Width Step m_GridX
                    For y As Integer = 0 To picCanvas.ClientSize.Height Step m_GridY
                        e.Graphics.DrawLine(m_PenGrid, x, y, x + 0.5F, y + 0.5F)
                    Next y
                Next x
            End If
    
            ' Draw existing lines.
            For i As Integer = 0 To m_Points1.Length - 1
                e.Graphics.DrawLine(m_PenOldLine, m_Points1(i), m_Points2(i))
            Next i
    
            ' Draw the new line.
            If m_Drawing Then
                e.Graphics.DrawLine(m_PenNewLine, m_X1, m_Y1, m_X2, m_Y2)
            End If
        End Sub
    
        ' Draw the top ruler.
        Private Sub picTopRuler_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picTopRuler.Paint
            e.Graphics.Clear(picTopRuler.BackColor)
    
            Dim y1 As Integer = picTopRuler.ClientSize.Height
            Dim y2 As Integer = (2 * picTopRuler.ClientSize.Height) \ 3
            Dim y3 As Integer = picTopRuler.ClientSize.Height \ 3
            Dim y4 As Integer = 0
            Dim x As Integer = 0
            For i As Integer = 0 To picTopRuler.ClientSize.Width \ m_GridX
                If i Mod 10 = 0 Then
                    e.Graphics.DrawLine(m_PenGrid, x, y1, x, y4)
                ElseIf i Mod 5 = 0 Then
                    e.Graphics.DrawLine(m_PenGrid, x, y1, x, y3)
                Else
                    e.Graphics.DrawLine(m_PenGrid, x, y1, x, y2)
                End If
                x += m_GridX
            Next i
    
            ' Show the mouse position.
            If m_Drawing Then
                e.Graphics.DrawLine(m_PenRulerDrawing, m_MouseX, y1, m_MouseX, 0)
            Else
                e.Graphics.DrawLine(m_PenRulerNormal, m_MouseX, y1, m_MouseX, 0)
            End If
        End Sub
    
        ' Draw the left ruler.
        Private Sub picLeftRuler_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picLeftRuler.Paint
            e.Graphics.Clear(picLeftRuler.BackColor)
    
            Dim x1 As Integer = picLeftRuler.ClientSize.Width
            Dim x2 As Integer = (2 * picLeftRuler.ClientSize.Width) \ 3
            Dim x3 As Integer = picLeftRuler.ClientSize.Width \ 3
            Dim x4 As Integer = 0
            Dim y As Integer = 0
            For i As Integer = 0 To picLeftRuler.ClientSize.Height \ m_GridY
                If i Mod 10 = 0 Then
                    e.Graphics.DrawLine(m_PenGrid, x1, y, x4, y)
                ElseIf i Mod 5 = 0 Then
                    e.Graphics.DrawLine(m_PenGrid, x1, y, x3, y)
                Else
                    e.Graphics.DrawLine(m_PenGrid, x1, y, x2, y)
                End If
                y += m_GridY
            Next i
    
            ' Show the mouse position.
            If m_Drawing Then
                e.Graphics.DrawLine(m_PenRulerDrawing, x1, m_MouseY, x4, m_MouseY)
            Else
                e.Graphics.DrawLine(m_PenRulerNormal, x1, m_MouseY, x4, m_MouseY)
            End If
        End Sub
    
        ' Show the mouse position on the rulers.
        Private Sub ShowMousePosition(ByVal X As Integer, ByVal Y As Integer)
            m_MouseX = X
            m_MouseY = Y
            picTopRuler.Invalidate()
            picLeftRuler.Invalidate()
        End Sub
    End Class
    
    i not want  moues ruler curve in form i want use moues ruler curve in background api 
    Tuesday, November 21, 2017 1:50 AM
  • Hi programmervb.net,

    Can you tell me if the picLeftRuler, picTopRuler, picCanvas are picturebox control, and  mnuOptionsShowGrid, mnuOptionsSnapToGrid are just button?

    >>i not want  moues ruler curve in form i want use moues ruler curve in background api 

    I am not sure what you want to do, can you give us one screenshot that can show something you want to do?

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 24, 2017 7:27 AM
    Moderator