怎么用VB做量角器?
怎么用VB做量角器?要有度数!
怎么用VB做量角器?要有度数!
答案:form1:Option Explicit
Private Sub Form_DblClick()
End
End SubPrivate Sub Form_Load()
Dim rtn As Long
Dim i As Integer
Dim h As Long
Dim d As Single
rtn = GetWindowLong(Me.hwnd, GWL_EXSTYLE) '取的窗口原先的样式
rtn = rtn Or WS_EX_LAYERED '使窗体添加上新的样式WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, rtn '把新的样式赋给窗体SetLayeredWindowAttributes Me.hwnd, 0, 150, LWA_ALPHA '把窗体设置成半透明样式,第二个参数表示透明程度
'取值范围0--255,为0时就是一个全透明的窗体了pi = Atn(1) * 4
d = pi / 180 * 2
xa = Me.Width / 2 / 15 '中心 X
ya = Me.Height / 2 / 15 '中心 Y
Shape1.Left = xa - Shape1.Width / 2 '中心点
Shape1.Top = ya - Shape1.Height / 2
For i = 0 To 110 '半圆多边形 点坐标数组
p(i).X = r * Cos((i - 5) * d) + xa
p(i).Y = -r * Sin((i - 5) * d) + ya
Next i
h = CreatePolygonRgn(p(3), 95, ALTERNATE) '创建半圆多边形
SetWindowRgn Me.hwnd, h, True '半圆多边形窗体
DeleteObject h
Hua 0 '画End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case Button
Case 1 '平移窗体
ReleaseCapture
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0
SetCapture Me.hwnd
Case 2
DownX = X
DownY = Y
End Select
End Sub
Private Sub Hua(An As Single) '画刻线
Dim r1 As Single
Dim i As Integer
Dim x1 As Single
Dim y1 As Single
Dim x2 As Single
Dim y2 As Single
Cls
Me.ForeColor = RGB(0, 60, 0)
r1 = 190
x1 = xa + r1 '1度
y1 = ya
For i = 0 To 179
Round x1, y1, -CSng(i), x2, y2, An
MoveToEx hdc, xa, ya, 0
LineTo hdc, x2, y2
Next i
Me.FillStyle = 0
Me.FillColor = Me.BackColor
Circle (xa, ya), 178, Me.BackColor
For i = 0 To 175 Step 5 '5度
Round x1, y1, -CSng(i), x2, y2, An
MoveToEx hdc, xa, ya, 0
LineTo hdc, x2, y2
Next i
Circle (xa, ya), 175, Me.BackColor
For i = 0 To 180 Step 10 '10度
Round x1, y1, -CSng(i), x2, y2, An
MoveToEx hdc, xa, ya, 0
LineTo hdc, x2, y2
Next i
Circle (xa, ya), 170, Me.BackColor
x1 = xa + 160 '十字线
Round x1, y1, 0, x2, y2, An
MoveToEx hdc, xa, ya, 0
LineTo hdc, x2, y2
x1 = xa + 155
Round x1, y1, 180, x2, y2, An
MoveToEx hdc, xa, ya, 0
LineTo hdc, x2, y2
Round x1, y1, -90, x2, y2, An
MoveToEx hdc, xa, ya, 0
LineTo hdc, x2, y2
x1 = xa + 15
Round x1, y1, 90, x2, y2, An
MoveToEx hdc, xa, ya, 0
LineTo hdc, x2, y2
Me.ForeColor = RGB(0, 60, 0)
x1 = xa + 165 '数字
Round x1, y1, -2.5, x2, y2, An
Z 20, 0, x2, y2, -An
x1 = xa + 155
Round x1, y1, -12, x2, y2, An
Z 120, 10, x2, y2, -An
Round x1, y1, -23, x2, y2, An
Z 230, 20, x2, y2, -An
Round x1, y1, -33, x2, y2, An
Z 330, 30, x2, y2, -An
Round x1, y1, -42, x2, y2, An
Z 420, 40, x2, y2, -An
Round x1, y1, -53, x2, y2, An
Z 530, 50, x2, y2, -An
Round x1, y1, -63, x2, y2, An
Z 630, 60, x2, y2, -An
Round x1, y1, -72, x2, y2, An
Z 720, 70, x2, y2, -An
Round x1, y1, -83, x2, y2, An
Z 830, 80, x2, y2, -An
Round x1, y1, -92.5, x2, y2, An
Z 920, 90, x2, y2, -An
x1 = xa + 170
Round x1, y1, -98, x2, y2, An
Z 2800, 100, x2, y2, -An
Round x1, y1, -108, x2, y2, An
Z 2900, 110, x2, y2, -An
Round x1, y1, -118, x2, y2, An
Z 3000, 120, x2, y2, -An
Round x1, y1, -127, x2, y2, An
Z 3100, 130, x2, y2, -An
Round x1, y1, -138, x2, y2, An
Z 3200, 140, x2, y2, -An
Round x1, y1, -148, x2, y2, An
Z 3300, 150, x2, y2, -An
Round x1, y1, -158, x2, y2, An
Z 3400, 160, x2, y2, -An
Round x1, y1, -168, x2, y2, An
Z 3500, 170, x2, y2, -An
Round x1, y1, -178, x2, y2, An
Z 3600, 180, x2, y2, -An
End Sub
上一个:VB里面的 .ocx文件是什么
下一个:VB懂得人来回答