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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:31:50+00:00 2026-05-20T02:31:50+00:00

I am making a Windows Forms app in C# for homework that accepts the

  • 0

I am making a Windows Forms app in C# for homework that accepts the length of a cube. It then displays the surface area and volume of the cube. That’s easy enough but it also needs to draw the cube.

What I’d like to know is the easiest way to draw the cube. I must do this with the Graphics class.

My thoughts on how to do it so far:

paper = myPicBox.CreateGraphics();
myPen = new Pen(Color.Black);
myPen.Width = 3;
paper.DrawRectangle(myPen, xCoord, yCoord, width, height);
paper.DrawLine(myPen, pointOne, pointTwo); // Then repeat this line for the four lines on the Z-axis
paper.DrawRectangle(myPen, xCoord, yCoord, width, height); // Where xCoord and yCoord have been changed to be placed at the end of the lines I've drawn

This is pretty bulky, so I was wondering if there was an easier or simpler way to achieve the same thing?

  • 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-20T02:31:51+00:00Added an answer on May 20, 2026 at 2:31 am

    As mentioned, that’s probably the best you’re going to get with WinForms. The best you can do is encapsulate your functionality into its own method such that you can draw more than one cube at once. So your DrawCube() method might take in an origin, length, and Graphics object and then draw it. The CreateGraphics call would come before any calls to DrawCube.

    Also, after you are done with your Graphics object, you should dispose of it by calling paper.Dispose() (see thispage) or stick it in a using block. Also, check out this website that explains when to use CreateGraphics (basically when you are drawing outside of a Paint event handler, which you are doing)

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

Sidebar

Related Questions

I got a Windows Forms app making use of Google Earth where users can
I'm making a MDI windows forms app and I have a panel inside the
I am making a c# windows app that has one MainForm and many User
While making some final tests of a class-library that I'm writing for Windows Mobile
I am making a project that should compile on Windows and Linux. I have
I am making an app in WPF in a style similar to Windows Explorer,
In one customer computer (windows vista) almost all forms of my app are oddly
I'm writing a web app that will be making requests via AJAX and would
I'm working on making an iPhone version of an Android app that I've written
I'm making a Windows Forms application in Visual Studio 2010 Ultimate, but can't get

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.