繪圖代碼寫在Paint事件中,如
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供芒市網(wǎng)站建設(shè)、芒市做網(wǎng)站、芒市網(wǎng)站設(shè)計(jì)、芒市網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、芒市企業(yè)網(wǎng)站模板建站服務(wù),十余年芒市做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g As Graphics = Me.CreateGraphics
g.DrawLine(Pens.Red, 100, 100, 200, 100)
End Sub
'方法二:在 PictureBox1上顯示圖像----圖畫在Bitmap
PictureBox1.Image = Nothing
Dim wid As Integer = PictureBox1.ClientSize.Width
Dim hgt As Integer = PictureBox1.ClientSize.Height
Dim bm As New Bitmap(wid, hgt)
Dim g As Graphics = Graphics.FromImage(bm)
'畫圖代碼
'畫圖代碼
PictureBox1.Image = bm
PictureBox1.Refresh()
g.Dispose()
'秒、分、時
Dim Second, Minute, Hour As Integer
'表的中心位置
Dim X0, Y0 As Integer
'
Dim X, Y As Variant
Private Sub Form_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
'按下鼠標(biāo)左鍵
If Button = 1 Then
'鼠標(biāo)指針在表盤內(nèi)
If X X0 - 950 And X X0 + 950 Then
If Y Y0 - 950 And Y Y0 + 950 Then
'移動表的位置
X0 = X
Y0 = Y
End If
End If
End If
Form1.Refresh
End Sub
Sub Form_Load()
'設(shè)置表的中心位置
Let X0 = 1100
Let Y0 = 1100
'時刻與對應(yīng)坐標(biāo)的轉(zhuǎn)換表
X = Array(0, 104, 207, 309, 406, 500, 587, _
669, 743, 809, 866, 913, 951, 978, 994, 1000, _
994, 978, 951, 913, 866, 809, 743, 669, 587, 500, 406, 309, 207, 104, 0, -105, -208, -310, -407, -500, -588, -670, -744, -810, -867, -914, -952, -979, -995, -1000, -995, -979, -952, -914, -867, -810, -744, -670, -588, -500, -407, -310, -208, -105, -1)
Y = Array(1000, 994, 978, 951, 913, 866, 809, 743, 669, 587, 500, 406, 309, 207, 104, 0, -105, -208, -310, -407, -500, -588, -670, -744, -810, -867, -914, -952, -979, -995, -1000, -995, -979, -952, -914, -867, -810, -744, -670, -588, -500, -407, -310, -208, -105, -1, 104, 207, 309, 406, 500, 587, 669, 743, 809, 866, 913, 951, 978, 994, 1000)
'初始化定時器
Timer1.Enabled = True
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
'繪制表盤
Circle (X0, Y0), 950, RGB(255, 255, 255)
'繪制刻度
DrawPlots
'定位時、分、秒針的起點(diǎn)
Line1.X1 = X0
Line1.Y1 = Y0
Line2.Y1 = Y0
Line2.X1 = X0
Line3.X1 = X0
Line3.Y1 = Y0
'秒
Second = Mid(Time, 7, 2)
'分
Minute = Mid(Time, 4, 2)
'時
Hour = Mid(Time, 1, 2)
If Hour 11 Then Hour = Hour - 12
Hour = Hour * 5 + (Hour / 12)
'定位時、分、秒針的終點(diǎn)
Line1.X2 = X(Second) * 0.9 + X0
Line1.Y2 = Y0 - Y(Second) * 0.9
Line2.X2 = X(Minute) * 0.8 + X0
Line2.Y2 = Y0 - Y(Minute) * 0.8
Line3.X2 = X(Hour) * 0.4 + X0
Line3.Y2 = Y0 - Y(Hour) * 0.4
End Sub
'繪制刻度
Sub DrawPlots()
For xx = 0 To 60
If (xx Mod 5) = 0 Then
Line (X(xx) + X0, Y(xx) + Y0)-(X(xx) * 1.1 + X0, Y(xx) * 1.1 + Y0), RGB(256, 256, 256)
End If
Next xx
End Sub 希望可以幫到你.!
你需要會用GDI+,也就是那個System.Drawing命名空間下的類.
給你說個思路,設(shè)Timer,到時間就用Form.Invalidate()函數(shù)重畫窗口,在重畫窗口的Form_Paint事件下面編寫代碼得到當(dāng)前時間,再根據(jù)當(dāng)前時間用GDI+畫時鐘.