自分のラインを自分のサークルの中に入れておきたい。
私のコード:
Public Class Form1
Public Function pt(ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer)
Dim b As Bitmap = New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(b)
g.DrawEllipse(Pens.Black, New Rectangle(x, y, h, w))
Me.BackgroundImage = b
Dim S As New Size
Dim loc As New Point
S.Width = 4
S.Height = 4
loc.X = x + w / 2 - 1
loc.Y = y + h / 2 - 1
Dim ptMove As New Panel
ptMove.Size = S
ptMove.Location = loc
ptMove.BackColor = Color.Aqua
Dim ptC As New Panel
ptC.Size = S
ptC.Location = New Point(loc.X, loc.Y - h / 2)
ptC.BackColor = Color.Red
Me.Controls.Add(ptC)
Me.Controls.Add(ptMove)
line(1, ptMove, ptC) ' < -- Draw The Line Between Two Point (I want To Keep Ptc Inside The Circle
Return True
End Function
Public Function line(ByVal w As Integer, ByVal pt1 As Panel, ByVal pt2 As Panel)
Dim b As Bitmap
b = Me.BackgroundImage
Dim g As Graphics
g = Graphics.FromImage(b)
g.DrawLine(Pens.Black, pt1.Location, pt2.Location)
Return True
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x, y, w, h As Integer
x = 200
y = 40
w = 100
h = 100
pt(x, y, w, h)
End Sub
End Class
結果:
2つのポイントがあります:
point 1
point 2
ポイント2:円の中心にあります。
ポイント1:円の端にあります。
ポイント1を新しい場所に移動するとします(たとえば0,0
):
g.DrawLine(Pens.Black, new point(0,0) , pt2.Location)
結果:
ラインはサークルから外れています
自分の内側の線を円に保ちたい。
線(ptCパネル)を円の半径内に保つにはどうすればよいですか?