[英]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. 我有一个棋盘游戏,它的大小是
500 (w) x 420 (h)
,我还有一个球,它的初始位置是w/2 and h
相对于x和y轴位于棋盘的中间底部。 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.
这对我完全没有意义,因为我只将球的y位置设置为等于高度。 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 您要使用的是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 ;)
您设置的大小包括所有周围的内容;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.