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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:53:40+00:00 2026-06-11T17:53:40+00:00

I have a homework, where I need to create a winforms game using C#.

  • 0

I have a homework, where I need to create a winforms game using C#. I have the following components:

  • Panel subclass with custom paint event
  • Panel with default windows UI elements.

I want them to arrange like this:

enter image description here

Because I draw on the center panel manually, I want to set it’s Width, and Height fixed, so the Form subclass, what will contain it, would show the whole panel.

I tried setting the size manually in the panel subclass:

Width = someFixedWidth;
Height = someFixedHeight;

Then adding it to the containing Form:

GamePanel panel = new GamePanel(...);
panel.Dock = DockStyle.Center;
this.AutoSize = true;
this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
this.Controlls.Add(panel);

Using this, I thought, that the form will respect the size of the Panel, but it just shrinks the window to so small, that nothing is visible, only the title.

So my question is, how would I be able to set the size of the GamePanel manually, and then dock it in the center of the form, so that the Form will respect the size I set, and doesn’t makes it smaller/bigger?

  • 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-11T17:53:41+00:00Added an answer on June 11, 2026 at 5:53 pm

    The Dock property is used to define the behavior of the component during resizing Container (Form) The way you did the screen is not centralized but is resized according to the screen changes, the ideal is to use a method to reposition the control and set its size. See this:

    SuspendLayout();
    
    Width = someFixedWidth;
    Height = someFixedHeight;
    
    panel.Size = new Size(panelWidth, panelHeight);
    
    panel.Location = new Point( ClientSize.Width / 2 - panelWidth / 2, ClientSize.Height / 2 - panelHeight / 2);
    panel.Anchor = AnchorStyles.None;
    panel.Dock = DockStyle.None;
    
    ResumeLayout();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given a homework assignment where I need to create a captcha
I need little help on a homework assignment. I have to create a 10
I need to create an array using a object using different format/structure I have:
I have a homework assignment where I need to take input from a file
Hi I have a homework assignment where I need to implement an intersection of
I have a Homework Planner application which I want to create an Alarm for
I have this homework problem where I need to use regex to remove every
So for Homework I have to create this program that reads from a text
First off, this isn't homework ;). I'm trying to create a wordsearch game from
I have homework which I have to use scriptlets in , I need to

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.