0

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

First run the program, the ball is no where to be found, but if I resize (increase) the height, I would find the ball is below

Hoang Minh
  • 1,066
  • 2
  • 21
  • 40
  • post a screenshot and a more complete code to replicate the problem... btw, winforms is not suitable for this to be honest... – walther Apr 13 '14 at 10:31
  • @walther: I just edited my original post. This is an assignment from my class, and it requires to use winforms. I already figured all everything, it's just the size the is not working as I expected. – Hoang Minh Apr 13 '14 at 10:43
  • What part of the ball are you setting the y-coordinate? If it's the top, then setting `ballrealcoordinatey = Height;` is outside the window. What happens if you set it to, say, 100? – John C Apr 13 '14 at 10:45

1 Answers1

1

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

Community
  • 1
  • 1
TomTom
  • 61,059
  • 10
  • 88
  • 148