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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:32:11+00:00 2026-05-31T15:32:11+00:00

I have a WinForms user control and I’m trying to draw 15 rows of

  • 0

I have a WinForms user control and I’m trying to draw 15 rows of 15 squares. If the size of the control changes, then the squares should get smaller, but still have 15 rows of 15 squares, like this pattern:

OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO

I am trying to use ClientSize.Width and ClientSize.Height to divide by 15, but its not coming out exactly right. Any help with this algorithm would be appreciated!

This is in C#, by the way.

Here is the code I have:

Graphics g = e.Graphics;

        g.DrawRectangle(Pens.Black, 0, 0, ClientSize.Width - 1, ClientSize.Height - 1);

        if (ClientSize.Width > ClientSize.Height)
        {
            int ndx = (int)Math.Ceiling(ClientSize.Height/15f);
            for (int x = 0; x < ClientSize.Width; x += ndx)
            {
                for (int y=0 ; y<ClientSize.Height; y+=ndx)
                {
                    g.DrawLine(Pens.Black, x, y, x + ndx, y);
                    g.DrawLine(Pens.Black, x, y, x, y + ndx);
                }
            }
        }
        else 
        {
            int ndx = (int)Math.Ceiling(ClientSize.Width / 15f);
            for (int x = 0; x < ClientSize.Width; x += ndx)
            {
                for (int y = 0; y < ClientSize.Height; y += ndx)
                {
                    g.DrawLine(Pens.Black, x, y, x + ndx, y);
                    g.DrawLine(Pens.Black, x, y, x, y + ndx);
                }
            }
        }
        g.Dispose();
  • 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-31T15:32:13+00:00Added an answer on May 31, 2026 at 3:32 pm

    Part of the problem is that your grid will only fit if the container’s width and height are exactly divisible by 15. Try rounding down.

    const int ColumnCount = 15;
    const int RowCount    = 15;
    int cellwidth  = (int)Math.Floor(ClientSize.Width  / ColumnCount);
    int cellheight = (int)Math.Floor(ClientSize.Height / RowCount   );
    

    After you draw your grid, explicitly blackout the area past the last row and column. You’ll have a thick black border but it will clearly define the 15×15 grid.

    If you want to avoid the black border, force the ClientSize.Width and .Height to be multiples of ColumnCount and RowCount respectively.

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

Sidebar

Related Questions

I have a WinForms user control Host with a custom UI Editor. Through that
I have several winforms listbox controls I am hosting in a user control. The
i have a winforms application. i have a user control with a lot of
I'm working on a WinForms app and I have a user control in it.
I have a custom WinForms control (inherits from control, i.e. without user interface jsut
I have a Winforms Gui in C# that allows a user to draw a
I have created a WinForms user control that is a set of five cascading
In .NET C# 3.5 Winforms, I have a user control with some simple child
I have a winforms app that uses a UserControl. The user control's job is
I have a user control that is hosting a winforms listbox. I am re-sorting

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.