Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:41:13+00:00 2026-06-11T23:41:13+00:00

I want to keep my line inside my circle. My code: Public Class Form1

  • 0

I want to keep my line inside my circle.

My code:

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

The result:

enter image description here

There are two points:

point 1
point 2

Point 2: in the center of the circle.

Point 1: on the edge of the circle.

Let’s say that I’m moving point 1 to a new location (for example 0,0):

g.DrawLine(Pens.Black, new point(0,0) , pt2.Location)

The result:

enter image description here

The Line is out from the circle

I want to keep the line inside me circle.

How can I keep the line (ptC panel) inside the radius of the circle?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:41:14+00:00Added an answer on June 11, 2026 at 11:41 pm

    You need to create a clipping region or path and apply it before drawing the line:

    Using g = Me.CreateGraphics()
    
        Using clip_path = New Drawing2D.GraphicsPath
            clip_path.AddEllipse(100, 100, 100, 100)
    
            g.DrawPath(Pens.Black, clip_path)
            g.SetClip(clip_path)
    
            g.DrawLine(Pens.Black, 0, 0, 150, 150)
        End Using
    
    End Using
    

    Here I’m drawing both the circle and the line, you might want to remove the call to DrawPath.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error in the $('#savetickets-list') line. I want to dynamically add
I usually want to keep my code as generic as possible. I'm currently writing
I've recently been writing some basic command-line programs (I want to keep my skills
I want to keep my footer at the bottom of the page while keeping
i want to keep my app in sync with the Server. The communication between
I want to keep an element always visible, even when it should be scrolled
I want to keep my list GWT side after fetch it from service side.For
I want to keep tabs on the number of concurrent users of my application.
I want to keep a cell selected, and only change when I select another
I want to keep SSH debug info separate (and logged) from other input. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.