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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:49:54+00:00 2026-05-26T20:49:54+00:00

so i have drawn a few objects , circles squares or even lines. This

  • 0

so i have drawn a few objects , circles squares or even lines. This is the code i use to draw the images:

Graphics surface = this.splitContainer1.Panel2.CreateGraphics();
Pen pen1 = new Pen(ColorR.BackColor, float.Parse(boxWidth.Text));

switch (currentObject)
{
case "line":
    if (step == 1)
    {
        splitContainer1.Panel2.Focus();
        one.X = e.X;
        one.Y = e.Y;
        boxX.Text = one.X.ToString();
        boxY.Text = one.Y.ToString();
        step = 2;
    }
    else
    {
        two.X = e.X;
        two.Y = e.Y;
        boxX2.Text = two.X.ToString();
        boxY2.Text = two.Y.ToString();
        surface.DrawLine(pen1, one, two);
        step = 1;
    }
    break;

case "circle":
    if (step == 1)
    {
        boxX.Text = e.X.ToString();
        boxY.Text = e.Y.ToString();
        step = 2;
    }
    else
    {
        int tempX = int.Parse(boxX.Text);
        int tempY = int.Parse(boxY.Text);
        int tempX2 = e.X;
        int tempY2 = e.Y;
        int sideX, sideY;
        if (tempX > tempX2)
        {
            sideX = tempX - tempX2;
        }
        else
        {
            sideX = tempX2 - tempX;
        }

        if (tempY > tempY2)
        {
            sideY = tempY - tempY2;
        }
        else
        {
            sideY = tempY2 - tempY;
        }

        double tempRadius;
        tempRadius = Math.Sqrt(sideX * sideX + sideY * sideY);
        tempRadius *= 2;

        bWidth.Text = bHeight.Text = Convert.ToInt32(tempRadius).ToString();

        surface.DrawEllipse(
           pen1,
           int.Parse(boxX.Text) - int.Parse(bWidth.Text) / 2, 
           int.Parse(boxY.Text) - int.Parse(bHeight.Text) / 2,
           float.Parse(bWidth.Text), float.Parse(bHeight.Text));
        step = 1;
    }
    break;

case "square":
    if (step == 1)
    {
        boxX.Text = e.X.ToString();
        boxY.Text = e.Y.ToString();
        step = 2;
    }
    else if (step == 2)
    {
        int tempX = e.X;
        if (tempX > int.Parse(boxX.Text))
        {
            bWidth.Text = (tempX - int.Parse(boxX.Text)).ToString();
        }
        else
        {
            bWidth.Text = (int.Parse(boxX.Text) - tempX).ToString();
        }

        step = 3;
    }
    else
    {
        int tempY = e.Y;
        if (tempY > int.Parse(boxY.Text))
        {
            bHeight.Text = (tempY - int.Parse(boxY.Text)).ToString();
        }
        else
        {
            bHeight.Text = (int.Parse(boxY.Text) - tempY).ToString();
        }

        surface.DrawRectangle(
            pen1,
            int.Parse(boxX.Text),
            int.Parse(boxY.Text),
            int.Parse(bWidth.Text),
            int.Parse(bHeight.Text));
        step = 1;
    }

    break;
}

So after I draw the images, I want to be able to select a figure and–for example–change the color or rotate it. But I cant seem to figure it out how to do it.

  • 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-26T20:49:55+00:00Added an answer on May 26, 2026 at 8:49 pm

    I suggest defining a base abstract shape class that has methods all shapes should provide, such as a method to draw itself on a graphics object, a method that says whether a point is within it / should could as selecting it, a method to rotate it by a given amount and a method to change the color.

    Once you’ve got your shape class then you’ve got to work out how to fill in the methods for each derived shape. For drawing you’ve already got the code. For selecting it, that will be dependent on the shape. For something like a circle it’s fairly easy, just calculate the distance between the center of the circle, and the point clicked, for something like a line it’s harder as you don’t want the user to have to click it exactly.

    That leaves rotating and changing the colour. Changing the colour is easy, just have a Color property on the Shape class, then when you draw your shapes, use that colour to create a brush or pen.

    As for rotation, take a look at Graphics.RotateTransform.


    public abstract class Shape
    {
        public Color Color { get; set; }
        public float Rotation { get; set; }
        public Point Position { get; set; }
    
        public Shape(Color color, float rotation, Point position)
        {
            Color = color;
            Rotation = rotation;
            Position = position;
        }
    
        public void ChangeRotation(float amount)
        {
            Rotation += amount;
        }
    
        public abstract void Draw(Graphics graphics);
        public abstract bool WithinBounds(Point point);
    }
    
    public class Circle : Shape
    {
        public float Radius { get; set; }
    
        public Circle(Color color, float rotation, Point position)
            :base(color, rotation, position)
        {
    
        }
    
        public override void Draw(Graphics graphics)
        {
    
        }
    
        public override bool WithinBounds(Point point)
        {
            if (Math.Sqrt(Math.Pow(point.X - Position.X, 2) + Math.Pow(point.Y - Position.Y, 2)) <= Radius)
                return true;
            else
                return false;
    
            // Note, if statement could be removed to become the below:
            //return Math.Sqrt(Math.Pow(point.X - Position.X, 2) + Math.Pow(point.Y - Position.Y, 2)) <= Radius;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be a simple one, basically I have a few paths drawn with
I have drawn something like this: How to remove the paths and points?
I have a MyCanvas class that extends JComponent. On this canvas I have drawn
I have an arrow drawn between two objects on a Winform. What would be
I have an owner-drawn list control in my Windows program. I use CListCtrl::GetBkColor to
If I have a few Program3D objects (each with it's own Vertex-Shader and Fragment-Shader
Hy.I drawn a skybox and a few objects inside it every thing is alright
I have a userControl which has some programmatically drawn rectangles. I need few instances
I have a simple portlet with a few components : 3 Button objects, 1
EDIT: A few people have said to use glNormal3f() to solve my lighting problem,

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.