-
Nov 21st, 2017, 03:14 PM
#1
Thread Starter
New Member
help in api mouse
hello
how use curve in ruler mouse
like this
-
Nov 21st, 2017, 05:18 PM
#2
Re: help in api mouse
I have no idea what you're talking about. Please provide a FULL and CLEAR explanation of the problem. Assume that too many words is better than not enough.
-
Nov 21st, 2017, 07:34 PM
#3
Thread Starter
New Member
Re: help in api mouse
Originally Posted by jmcilhinney
I have no idea what you're talking about. Please provide a FULL and CLEAR explanation of the problem. Assume that too many words is better than not enough.
Code:
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 want create new curve lines
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|