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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:20:27+00:00 2026-06-02T15:20:27+00:00

I have a problem with my C# Windows-Forms project. I am trying to draw

  • 0

I have a problem with my C# Windows-Forms project. I am trying to draw a square and I want to display the square inside a picture-box. How can I do that?

This is my function for drawing the square:

public void DrawingSquares(int x, int y)//the function gets x and y to know where to print the square.
    {
        Graphics graphicsObj;
        graphicsObj = this.CreateGraphics();
        Pen myPen = new Pen(Color.Black, 5);
        Rectangle myRectangle = new Rectangle(x, y, 100, 100);
        graphicsObj.DrawRectangle(myPen, myRectangle);
    }
  • 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-06-02T15:20:28+00:00Added an answer on June 2, 2026 at 3:20 pm

    my vs solution

    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
        public Form1()
        {
            InitializeComponent();
    
            this.pictureBox1.Image = this.Draw(this.pictureBox1.Width, this.pictureBox1.Height);
        }
    
        public Bitmap Draw(int width, int height)
        {
            var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            var graphics = Graphics.FromImage(bitmap);
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.FillRectangle(new SolidBrush(Color.Tomato), 10, 10, 100, 100);
    
            return bitmap;
        }
      }
    }
    

    this is my Form1.cs

    you should have something simillar

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

Sidebar

Related Questions

I've got yet another deployment problem. What I have: little Windows Forms application that
I have setup a windows forms project to use localization so that it will
Following is my problem: I have a custom UserControl in my Windows Forms Project.
I have a problem with a ClickOnce deployment of a Windows Forms application. When
I have encountered a rather nasty problem with the DataGridView control (Windows.Forms, .NET Framework
I'm having problem when running my Windows Forms program. In the program, I have
I have a little demonstration below of a peculiar problem. using System; using System.Windows.Forms;
On Windows I have a problem I never encountered on Unix. That is how
Currently I am working with: C# Windows forms application I currently have a problem
I have no problems setting up a regular (Windows Forms or Console) project in

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.