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 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 am making a c# windows app that has one MainForm and many User
I'm making another app's window topmost to ensure that a click in my app
I am making an app that scrolls information on the desktop. The window is
I have a windows forms application that reads and updates an XML file with
I'm working on making an iPhone version of an Android app that I've written
I am making a windows forms project in C#, in which I made a
I am making a windows forms application. I am using a TreeView to display
I'm making a program which the user build directories (not in windows, in my
After making a few modifications to a rails app I am tinkering on, railroad

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.