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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:53:08+00:00 2026-05-26T16:53:08+00:00

Question: How do i draw a rectangle on a Panel, rather than a form.

  • 0

Question: How do i draw a rectangle on a Panel, rather than a form. Here is what my code looks like:

 /* 
  * based on a some flags i determine which shape i want to draw. 
  * All shapes are stored in a list. I loop through the list 
  * and call each shape specific draw method - as shown below:.
  *
  */
namespace myDrawProgram
{
     private void panelArea_Paint(object sender, PaintEventArgs e)
        {
            if (drawWithPaint == true)
            {
                Pen p = new Pen(Color.Blue);
                p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

                if (IsShapeRectangle == true)
                {
                    e.Graphics.DrawRectangle(p, rect);
                }
                else if (IsShapeCircle == true)
                {
                    e.Graphics.DrawEllipse(p, rect);
                }

            }
            foreach (Shapes shape in listOfShapes)
            {

                shape.Draw(e.Graphics);
            }
        }
}

/*
 * In another file i have my class which deals with 
 * drawing rectangles. It is as follows: 
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using SETPaint; 

namespace myDrawProgram
{
    class TheRectangles : Shapes
    {
        public Rectangle MyRect { set; get; }

        public TheRectangles(Rectangle rect, Color colour, Color boarderColour, Int32 brushThickness)
            : base(colour, boarderColour, brushThickness)
        {
            MyRect = rect;

        }


        public override void Draw(Graphics g)
        {
            base.Draw(g);


            g.FillRectangle(new SolidBrush(Shapes.c), MyRect);
            g.DrawRectangle(new Pen(bc, MyBrushThickness), MyRect);
        }
    }
}

i’m assuming i need to do something like this:

using (Graphics g = this.panel1.CreateGraphics()) {}

I’m just not sure how to implement this with regards to my code…

  • 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-26T16:53:09+00:00Added an answer on May 26, 2026 at 4:53 pm

    It sounds like you haven’t hooked up the paint event of the panel:

    panelArea.Paint += new PaintEventHandler(panelArea_Paint);
    

    If panelArea is the name of your form, then just change it to your panel:

    panel1.Paint += new PaintEventHandler(panel1_Paint);
    

    and then move your painting logic to that method:

    private void panel1_Paint(object sender, PaintEventArgs e) {
      // the rest of your drawing
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

before question think about for example photoshop. When you draw a rectangle on the
Terminology question ! In many graphics packages the user can draw a line between
My main question is given a feature centroid, how can I draw it in
the pixman image library can draw radial color gradients between two circles. I'd like
The question I have here is sort of a 2 parter. I have a
I'm trying to let people draw a rectangle on Google Maps and store the
So on my program, I draw 2D rectangle using GLSL shader. The rectangle is
Pretty simple Question, unfortunatly never used draw controls etc in C# so im not
I want to draw some data into a texture: many items in a row.
Here is my class I made to draw a HUD: using System; using System.Collections.Generic;

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.