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 8705985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:30:02+00:00 2026-06-13T03:30:02+00:00

How would one go about achieving a line that will connect two rectangles together?

  • 0

How would one go about achieving a line that will connect two rectangles together? At the moment, I have this:

if (listBox1.Items.Count >= 2)
{
    e.Graphics.DrawLine(Pens.AliceBlue, new Point(/*??*/), new Point(n._x, n._y));                    
}

With the second new Point being where I placed my new Rectangle but I am not sure how to get the point of the Rectangle beforehand.

My rectangles X and Y are stored in a list like so:

public BindingList<Node> nodeList = new BindingList<Node>();

My main goal would be too add a line to each of my rectangles as they are drawn.

For example: Place one rectangle down, nothing happens, place another one down, add a line connecting the two, add a third, add a line connecting the second and third one together. But if I can get one going I can try and work out how to continuously add these lines.

Thanks for any help!

  • 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-13T03:30:03+00:00Added an answer on June 13, 2026 at 3:30 am

    If you have a list of Rectangles, you can draw them with lines connecting them like this:

    void drawRectangles(Graphics g, List<Rectangle> list) {
        if (list.Count == 0) {
            return;
        }
    
        Rectangle lastRect = list[0];
        g.DrawRectangle(Pens.Black, lastRect);
    
        // Indexing from the second rectangle -- the first one is already drawn!
        for (int i = 1; i < list.Count; i++) {
            Rectangle newRect = list[i];
            g.DrawLine(Pens.AliceBlue, new Point(lastRect.Right, lastRect.Bottom), new Point(newRect.Left, newRect.Top));
            g.DrawRectangle(Pens.Black, newRect);
            lastRect = newRect;
        }
    }
    

    You may insert some smart code to decide which corners to connect, but that’s up to you.

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

Sidebar

Related Questions

How would one go about achieving one of these two ways for automation? 1,
How would one go about proving to management that a batch reformat of all
How would one go about defining something like this in an xsd? <start> <request
How would one go about writing a query that selects items 2000-2010 out of
How would one go about doing this? Also, is there an easy way to
How would one go about keep an object in memory such that it won't
How would one go about detecting if two images on the screen (form) were
How would one go about retrieving a dependent/parent object from an entity. $person->getAddress(); This
How would one go about handling a situation like this? Having more than one
How would one go about having a multi step type form with zend. This

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.