建立新窗體,新建timer控件,間隔隨意,運(yùn)行即可,輸入以下代碼,可以充分看到你要的效果
創(chuàng)新互聯(lián)建站主營(yíng)寧晉網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP開(kāi)發(fā),寧晉h5微信小程序開(kāi)發(fā)搭建,寧晉網(wǎng)站營(yíng)銷推廣歡迎寧晉等地區(qū)企業(yè)咨詢
Dim?yuanxin?As?New?Point(50,?50)?'圓心
Dim?zhijing?As?Long?=?100?'直徑,其實(shí)里面用的多的是半徑,但你說(shuō)是直徑,我就用直徑
Private?Sub?Form1_Paint(sender?As?Object,?e?As?PaintEventArgs)?Handles?Me.Paint
e.Graphics.Clear(Color.Beige)?'刷除底色
Dim?myRect?As?New?RectangleF(150,?80,?100,?100)?'建立矩形
e.Graphics.DrawRectangle(Pens.Red,?Rectangle.Round(myRect))?'畫出矩形
Dim?p?As?System.Drawing.Drawing2D.GraphicsPath?=?New?System.Drawing.Drawing2D.GraphicsPath()?'新建路徑
p.AddEllipse(yuanxin.X?-?zhijing?\?2,?yuanxin.Y?-?zhijing?\?2,?zhijing,?zhijing)?'向當(dāng)前路徑增加橢圓,里面的運(yùn)算是把圓心轉(zhuǎn)換為圓形外切矩形的左上角坐標(biāo)以及這個(gè)矩形的寬和高,在本例中寬高即為圓形的直徑
e.Graphics.DrawPath(Pens.Black,?p)?'在窗體上畫出橢圓(本例中是圓形)
Dim?myRegion?As?New?[Region](p)?'根據(jù)橢圓建立區(qū)域
Dim?contained?As?Boolean?=?myRegion.IsVisible(myRect)?'判斷區(qū)域是否相交
Dim?myFont?As?New?Font("Arial",?8)
Dim?myBrush?As?New?SolidBrush(Color.Black)
e.Graphics.DrawString("相交?=?"??contained.ToString(),?myFont,?myBrush,?New?PointF(20,?260))?'輸出結(jié)果
End?Sub
Private?Sub?Timer1_Tick(sender?As?Object,?e?As?EventArgs)?Handles?Timer1.Tick
yuanxin.X?+=?1
Me.Refresh()
End?Sub
既然會(huì)畫直線了,那就應(yīng)該會(huì)畫箭頭了(兩條短直線相交就能成箭頭 )
標(biāo)序號(hào)其實(shí)就是算出位置寫字
可用數(shù)學(xué)的方法,如果一條直線的兩個(gè)端點(diǎn)都在另一直線的同一側(cè),則沒(méi)有交叉,否則,就有交叉。代碼如下:
Private Sub Command1_Click()
Dim X1 As Long, Y1 As Long, X2 As Long, Y2 As Long
Dim A1 As Long, B1 As Long, A2 As Long, B2 As Long
Dim a As Long, b As Long
X1 = Line1.X1: X2 = Line1.X2: Y1 = Line1.Y1: Y2 = Line1.Y2
A1 = Line2.X1: A2 = Line2.X2: B1 = Line2.Y1: B2 = Line2.Y2
a = F(X1, Y1, X2, Y2, A1, B1)
b = F(X1, Y1, X2, Y2, A2, B2)
If a * b = 0 Then
Print "兩直線有交叉。"
ElseIf a * b 0 Then
Print "兩直線沒(méi)有交叉。"
Else
a = F(A1, B1, A2, B2, X1, Y1)
b = F(A1, B1, A2, B2, X2, Y2)
If a * b = 0 Then
Print "兩直線有交叉。"
Else
Print "兩直線沒(méi)有交叉。"
End If
End If
End Sub
Private Function F(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X As Long, ByVal Y As Long) As Long
Dim K As Long
K = (Y2 - Y1) * X - (X2 - X1) * Y + X2 * Y1 - X1 * Y2
F = Sgn(K)
End Function
dim myGraphics as new
System.Drawing .Graphics
Dim myStartPoint As New Point(4, 2)
Dim myEndPoint As New Point(12, 6)
myGraphics.DrawLine(myPen, myStartPoint, myEndPoint)