简体   繁体   中英

Why is the windows form size different from its setting in C#?

I have a board game and its size is 500 (w) x 420 (h) and I also have a ball, whose initial position is w/2 and h relative to x and y axis which is at the middle bottom of the board. However, when I run the program, the ball is always placing below out of the window. That would make no sense at all to me since I only set the y position of the ball equal to height. Is it a glitch or am I doing anything wrong in here ? Here is my snipet code:

private double ballrealcoordinatex;  //Ball's x coordinate measured in real numbers
private double ballrealcoordinatey;  //Ball's y coordinate measured in real numbers
private int ballintx;   //The integer x-coordinate of the ball
private int ballinty;   //The integer y-coordinate of the ball

public Form1()
{
       InitializeComponent();
       //Set start position of the ball
       ballrealcoordinatex = (double)(Width / 2 - ballradius);
       ballrealcoordinatey = Height; // (double)(Height / 2 - ballradius);
       ballintx = (int)System.Math.Round(ballrealcoordinatex);
       ballinty = (int)System.Math.Round(ballrealcoordinatey);
}

首先运行程序,找不到球,但是如果我调整大小(增加)高度,我会发现球在下面

You see the nice blue frame around the window? There you go - THAT is the window size.

What you want to work with is the ClientSize

How do I set the size of the visible area of a form, minus heading and borders?

has more explanation. The size you set includes all the surrounding ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM