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

  • Home
  • SEARCH
  • 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 7057519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:59:45+00:00 2026-05-28T03:59:45+00:00

I can’t seem to make DrawBorder to work when passing a new rectangle object

  • 0

I can’t seem to make DrawBorder to work when passing a new rectangle object to it:

private void answered_choice_1_paint(object sender, PaintEventArgs e)
{
    Size s = new Size(Math.Max(answered_choice_1.Height, icon_correct.Height) + 4,  answered_choice_1.Width + 22 + this.default_margin + 4);
    Point p = new Point(answered_choice_1.Location.X - 22 - this.default_margin - 2, answered_choice_1.Location.Y - 2);
    Rectangle r = new Rectangle(p, s);
    if (icon_correct.Location.Y == answered_choice_1.Location.Y)
    {
        ControlPaint.DrawBorder(e.Graphics, r, Color.Green, ButtonBorderStyle.Solid);
    }
}

However, passing a label’s rectangle works:

private void answered_choice_1_paint(object sender, PaintEventArgs e)
{
    if (icon_correct.Location.Y == answered_choice_1.Location.Y)
    {
        ControlPaint.DrawBorder(e.Graphics, answered_choice_1.DisplayRectangle, Color.Green, ButtonBorderStyle.Solid);
    }
}

As you can see from the code, my intent is to draw a rectangular border around the answered_choice_1 label and icon_correct pictureBox, so the second code excerpt does draw a rectangle but I want to draw the rectangle from the first excerpt.

Edit:
I’ve narrowed it down to this:

int x,y;
x = answered_choice_1.Location.X - 22 - this.default_margin - 2;
y = answered_choice_1.Location.Y - 2;
Point p = new Point(x, y);

Using the debugger I’ve found out that answered_choice_1.Location.Y - 2 evaluates to 210 buy y gets the value 0; This is very strange but consistent: if I call a different constructor for the Rectangle r, I get the same outcome.

Any further help would be appreciated.

Second Edit The edit before was wrong, although that’s the data that I saw in the Visual Studio IDE. Humberto’s comment gave me the final clue to what was going on, and I’ve approved his answer.

  • 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-05-28T03:59:45+00:00Added an answer on May 28, 2026 at 3:59 am

    I think you’re trying to paint a border around a pair of controls: an icon aligned to the left of a label. Is this the case?

    +------------------------------+
    |                              |
    | ICON   answered_choice_1     |---> border on a 4px margin around both controls
    |                              |
    +------------------------------+
    ^        ^
    |  22px  |
    

    If so, your painting code has a problem. It’s trying to use the “surface” (Graphics instance) of answered_choice_1 to paint outside its area. It won’t work.

    Instead, you can place the icon and the label inside a Panel, then paint the panel’s border whenever you need. Somewhat like you already did, but referring to panel_1 instead of answered_choice_1:

    private void panel_1_paint(object sender, PaintEventArgs e)
    {
        if (icon_correct.Location.Y == answered_choice_1.Location.Y)
        {
            ControlPaint.DrawBorder(e.Graphics, panel_1.DisplayRectangle,  Color.Green, ButtonBorderStyle.Solid);
        }
    }
    

    Alternatively, you can assign a FixedSingle border style to the panel, but AFAIK the border color will be system defined.

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

Sidebar

Related Questions

Can't work out a way to make an array of buttons in android. This
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can some one Guide me to work with these things... What is Model popup
can anyone tell me if it is possible to convert a dojo charting object
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can anyone help me trying to find out why this doesn't work. The brushes
can someone show me the regex for this preg_match. I want to make sure
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can you set the internal [[Class]] property of an ECMAScript object?
Can somebody point me to a resource that explains how to go about having

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.