Private Sub PictureBox2_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox2.Paint
創(chuàng)新互聯(lián)公司是一家專(zhuān)業(yè)提供沁陽(yáng)企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都做網(wǎng)站、成都網(wǎng)站建設(shè)、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為沁陽(yáng)眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)的建站公司優(yōu)惠進(jìn)行中。
Dim points As New List(Of Point)
points.Add(New Point(0, 0))
points.Add(New Point(1, 10))
points.Add(New Point(3, 15))
points.Add(New Point(14, 0))
points.Add(New Point(20, 60))
points.Add(New Point(40, 20))
points.Add(New Point(70, 50))
e.Graphics.DrawCurve(Pens.Red, points.ToArray)
End Sub
供參考,points可設(shè)為全局變量,那樣add隨便在哪增加,想要看見(jiàn)看上去動(dòng)態(tài)的圖,那就在新增完n個(gè)后,繼續(xù)增加n+1個(gè)之時(shí),放棄points中的第一個(gè)。
scale(x1,y1)-(x2,y2)
你只要記住,這里的x1,y1是左上角的坐標(biāo),x2,y2是右下角的坐標(biāo),通過(guò)這兩個(gè)點(diǎn)的坐標(biāo)設(shè)定,就可以決定坐標(biāo)原點(diǎn)的位置以及坐標(biāo)軸的方向了,比如
Scale (-300,200)-(300,-200)
以上是把坐標(biāo)原點(diǎn)設(shè)在窗體中心,x軸長(zhǎng)600,方向從左到右,y軸長(zhǎng)400,方向從下向上。
Scale (800,0)-(0,600)
以上是把坐標(biāo)原點(diǎn)設(shè)在窗體右上角,x軸長(zhǎng)800,方向從右到左,y軸長(zhǎng)600,方向從上向下。
下面說(shuō)坐標(biāo)軸和原點(diǎn)的標(biāo)示法:
假定自定義坐標(biāo)設(shè)為:
Scale (-300, 200)-(300, -200)
則
Line (-300, 0)-(300, 0) '畫(huà)x軸
Line (0, 200)-(0, -200) '畫(huà)y軸
CurrentX = 290
CurrentY = -5
Print "x" '標(biāo)示x軸
CurrentX = 5
CurrentY = 200
Print "y" '標(biāo)示y軸
CurrentX = 5
CurrentY = -5
Print "0" '標(biāo)示原點(diǎn)
Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long '全屏坐標(biāo)聲明
Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpPoint As POINTAPI) As Int32 '窗口坐標(biāo)聲明
Private Structure POINTAPI '聲明坐標(biāo)變量
Public x As Int32 '聲明坐標(biāo)變量為32位
Public y As Int32 '聲明坐標(biāo)變量為32位
End Structure
'以上是聲明部分
'以下是窗口部分
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '用時(shí)鐘控件來(lái)取坐標(biāo),窗口上放個(gè)Timer組件,Enabled為允許,周期為10到100毫秒均可
Dim P As POINTAPI '聲明坐標(biāo)變量
Dim xx, yy '聲明轉(zhuǎn)換要用到的變量
GetCursorPos(P) '獲取鼠標(biāo)在屏幕中的位置
ScreenToClient(Me.Handle.ToInt32, P) '轉(zhuǎn)換為本窗體的坐標(biāo)
xx = P.x.ToString '把X轉(zhuǎn)換成能顯示到文本框的字符串格式
yy = P.y.ToString '把Y轉(zhuǎn)換成能顯示到文本框的字符串格式
TextBox1.Text = xx + "和" + yy '文本框的內(nèi)容為X坐標(biāo)和Y坐標(biāo)
End Sub
窗體上放一個(gè)textbox 兩條line 一個(gè)label 代碼粘貼 運(yùn)行 即見(jiàn)效果
'*************************************************************************
'**工程名稱(chēng):平面座標(biāo)
'**說(shuō) 明:小鳥(niǎo)工作室 版權(quán)所有2007 - 2008(C)1
'**創(chuàng) 建 人:秋色烽火
'**日 期:2007-12-18 14:08:15
'**版 本:V1.0.0
'*************************************************************************
Const DPITCH = 300 '點(diǎn)距
Dim WithEvents oControlx1 As Line
Dim WithEvents oControlx2 As Line
Dim WithEvents oControly1 As Line
Dim WithEvents oControly2 As Line
Dim WithEvents oControlShape As Shape
Dim WithEvents oControlPixinfo As Label
Dim DPCound%, PixID%, PixBackColor, dotx%, doty%
Private Sub Form_Load()
Me.Caption = "平面座標(biāo) - by 秋色烽火[小鳥(niǎo)工作室]"
Me.Height = 9300
Me.Width = 9300
Line1.X1 = 150
Line1.X2 = Me.Width - 150
Line1.Y1 = Me.Height / 2
Line1.Y2 = Line1.Y1
Line2.Y1 = 150
Line2.Y2 = Me.Height - 150
Line2.X1 = Me.Width / 2
Line2.X2 = Line2.X1
Label1.Width = 255
Label1.Height = 255
Label1.AutoSize = ture
Label1.BackStyle = 0
Label1.FontItalic = True
Label1.FontBold = True
Label1.FontSize = 10
Label1.ForeColor = HFF
Label1.Caption = "O"
Label1.Left = Me.Width / 2 + Label1.Width - 100
Label1.Top = Me.Height / 2 - Label1.Height
Text1.Text = ""
Call AddLine
Text1.ToolTipText = "請(qǐng)輸入整數(shù)座標(biāo)(x,y) 中間用英文逗號(hào)分隔~(yú)~~,雙擊文本框或回車(chē)開(kāi)始標(biāo)注" vbCrLf " 右擊顯示幫助信息 " vbCrLf "輸入座標(biāo)請(qǐng)介乎于" DPCound \ 2 "至" -1 * DPCound \ 2 "之間~~"
PixID = 0
End Sub
Sub AddLine()
DPCound = (Me.Width - 300) / DPITCH - 2
For i = DPCound \ 2 + 1 To DPCound
Set oControlx1 = Controls.Add("VB.Line", "lineW" i, Me)
Set oControlx2 = Controls.Add("VB.Line", "lineW" DPCound \ 2 - (i - (DPCound \ 2 + 1)), Me)
Set oControly1 = Controls.Add("VB.Line", "lineH" i, Me)
Set oControly2 = Controls.Add("VB.Line", "lineH" DPCound \ 2 - (i - (DPCound \ 2 + 1)), Me)
With oControlx1
.Visible = True '顯示
.X1 = Me.Width / 2 + (i - DPCound \ 2) * DPITCH
.X2 = Me.Width / 2 + (i - DPCound \ 2) * DPITCH
.Y1 = Me.Height / 2 - 60
.Y2 = Me.Height / 2 + 60
End With
With oControlx2
.Visible = True '顯示
.X1 = Me.Width / 2 - (i - DPCound \ 2) * DPITCH
.X2 = Me.Width / 2 - (i - DPCound \ 2) * DPITCH
.Y1 = Me.Height / 2 - 60
.Y2 = Me.Height / 2 + 60
End With
With oControly1
.Visible = True '顯示
.Y1 = Me.Height / 2 + (i - DPCound \ 2) * DPITCH
.Y2 = Me.Height / 2 + (i - DPCound \ 2) * DPITCH
.X1 = Me.Width / 2 - 60
.X2 = Me.Width / 2 + 60
End With
With oControly2
.Visible = True '顯示
.Y1 = Me.Height / 2 - (i - DPCound \ 2) * DPITCH
.Y2 = Me.Height / 2 - (i - DPCound \ 2) * DPITCH
.X1 = Me.Width / 2 - 60
.X2 = Me.Width / 2 + 60
End With
Next
End Sub
Sub AddPix()
If InStr(Text1.Text, ",") 0 Then
If IsNumeric(Mid$(Text1.Text, 1, InStr(Text1.Text, ",") - 1)) And IsNumeric(Mid$(Text1.Text, InStr(Text1.Text, ",") + 1, Len(Text1.Text))) Then
If CInt(Mid$(Text1.Text, 1, InStr(Text1.Text, ",") - 1)) = DPCound \ 2 And CInt(Mid$(Text1.Text, 1, InStr(Text1.Text, ",") - 1)) = -1 * DPCound \ 2 Then
PixID = PixID + 1
Set oControlShape = Controls.Add("VB.Shape", "Pix" PixID, Me)
Set oControlPixinfo = Controls.Add("VB.Label", "Pixinfo" PixID, Me)
With oControlShape
.Visible = True '顯示
.Shape = 3
'.BorderColor = HFF
.BackColor = HFF 'RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255)) 'HFF
.BackStyle = 1
.BorderStyle = 0
.Width = 75
.Height = 75
.Left = Me.Width / 2 + CInt(Mid$(Text1.Text, 1, InStr(Text1.Text, ",") - 1)) * DPITCH
.Top = Me.Height / 2 - CInt(Mid$(Text1.Text, InStr(Text1.Text, ",") + 1, Len(Text1.Text))) * DPITCH
dotx = .Left
doty = .Top
PixBackColor = .BackColor
End With
With oControlPixinfo
.Visible = True '顯示
.BackStyle = 0
' .FontItalic = True
'.FontBold = True
.FontSize = 9
.ForeColor = HFF 'PixBackColor 'HFF
.Caption = "[" PixID "]" CStr(CInt(Mid$(Text1.Text, 1, InStr(Text1.Text, ",") - 1))) "," CInt(Mid$(Text1.Text, InStr(Text1.Text, ",") + 1, Len(Text1.Text)))
.Width = 1000
.Height = 255
.Left = dotx
.Top = doty - .Height
.AutoSize = ture
End With
Text1.Text = ""
Else
MsgBox "輸入座標(biāo)請(qǐng)介乎于" DPCound \ 2 "至" -1 * DPCound \ 2 "之間~~", , "錯(cuò)誤"
Text1.Text = ""
End If
Else
MsgBox "座標(biāo)請(qǐng)使用數(shù)字輸入", , "錯(cuò)誤"
Text1.Text = ""
End If
Else
MsgBox "輸入的座標(biāo)請(qǐng)使用英文逗號(hào) , 進(jìn)行分隔", , "錯(cuò)誤"
Text1.Text = ""
End If
End Sub
Sub init()
If PixID 0 Then
If MsgBox("確實(shí)要清空所有標(biāo)注點(diǎn)嗎?", vbOKCancel + vbInformation + vbDefaultButton2 + vbMsgBoxSetForeground + vbSystemModal, "信息!") = vbOK Then
For i = 1 To PixID
Controls.Remove "Pix" i
Controls.Remove "Pixinfo" i
Next
PixID = 0
End If
End If
End Sub
Private Sub Text1_DblClick()
Call AddPix
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Call AddPix
End If
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
MsgBox "請(qǐng)輸入整數(shù)座標(biāo)(x,y) 中間用英文逗號(hào)分隔~(yú)~~,雙擊文本框或回車(chē)開(kāi)始標(biāo)注" vbCrLf "輸入座標(biāo)請(qǐng)介乎于" DPCound \ 2 "至" -1 * DPCound \ 2 "之間~~" vbCrLf "中鍵清空所有創(chuàng)建的座標(biāo)", , "幫助"
End If
If Button = 4 Then
Call init
End If
End Sub
'好玩的東東
'****************************
'如果加上下面的就好羅
'定時(shí)設(shè)為500
'Dim a, b As Integer
'a = 14
'b = 14
'Private Sub Timer1_Timer()
'Text1.Text = a "," b
'a = a - 1
'b = b - 1
'Call Text1_KeyDown(13, 1)
'End Sub