十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
建立新窗体,新建timer控件,间隔随意,运行即可,输入以下代码,可以充分看到你要的效果
创新互联建站主营宁晋网站建设的网络公司,主营网站建设方案,重庆APP开发,宁晋h5微信小程序开发搭建,宁晋网站营销推广欢迎宁晋等地区企业咨询
Dim yuanxin As New Point(50, 50) '圆心
Dim zhijing As Long = 100 '直径,其实里面用的多的是半径,但你说是直径,我就用直径
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) '向当前路径增加椭圆,里面的运算是把圆心转换为圆形外切矩形的左上角坐标以及这个矩形的宽和高,在本例中宽高即为圆形的直径
e.Graphics.DrawPath(Pens.Black, p) '在窗体上画出椭圆(本例中是圆形)
Dim myRegion As New [Region](p) '根据椭圆建立区域
Dim contained As Boolean = myRegion.IsVisible(myRect) '判断区域是否相交
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)) '输出结果
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
yuanxin.X += 1
Me.Refresh()
End Sub
既然会画直线了,那就应该会画箭头了(两条短直线相交就能成箭头 )
标序号其实就是算出位置写字
可用数学的方法,如果一条直线的两个端点都在另一直线的同一侧,则没有交叉,否则,就有交叉。代码如下:
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 "两直线没有交叉。"
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 "两直线没有交叉。"
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)