【问题标题】:Why is the windows form size different from its setting in C#?为什么窗体大小与 C# 中的设置不同?
【发布时间】:2014-05-27 07:40:30
【问题描述】:

我有一个棋盘游戏,它的大小是500 (w) x 420 (h),我还有一个球,它的初始位置是w/2 and h,相对于棋盘中间底部的x 和y 轴。但是,当我运行程序时,球总是放在窗外。这对我来说毫无意义,因为我只将球的 y 位置设置为等于高度。这是一个小故障还是我在这里做错了什么? 这是我的代码片段:

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);
}

【问题讨论】:

  • 张贴截图和更完整的代码来复制问题...顺便说一句,winforms 不适合这个老实说...
  • @walther:我刚刚编辑了我的原始帖子。这是我班上的作业,需要使用winforms。我已经想通了一切,只是尺寸没有按我预期的那样工作。
  • 您在球的哪个部分设置 y 坐标?如果它是顶部,则设置ballrealcoordinatey = Height; 在窗口之外。如果将其设置为 100 会发生什么?

标签: c# winforms


【解决方案1】:

你看到窗户周围漂亮的蓝框了吗?你去 - 那是窗口大小。

您要使用的是 ClientSize

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

有更多解释。您设置的大小包括所有周围;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 2015-03-08
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多