# DrawRectangle

## Recommended Posts

Hey

So i would like to draw a rectangle at the bottom of the screen, (height: 25, and width: 100%).

Now my question, is how do i know which value to set for the X and Y, so the rectangle is at the bottom of the screen ?

Thanks.

Edited by nordi
##### Share on other sites

I managed to find: Game.Resolution.Width for the Width, but still no clue for the X and Y ...

##### Share on other sites

if im not wrong X must be half screen width, Y must be the screen height - half rectangle height

the X and Y are the center of the rectangle

##### Share on other sites

x and y is for the position on screen, u should calculate x and y, width and height of the rectangle from Game.Resolution in order to position and size the same relative to different resolutions.

the range of x and y is... (0, 0) is top left of the screen and (Resolution Width, Resolution Height) is bottom right corner of screen

##### Share on other sites

x and y is for the position on screen, u should calculate x and y, width and height of the rectangle from Game.Resolution in order to position and size the same relative to different resolutions.

the range of x and y is... (0, 0) is top left of the screen and (Resolution Width, Resolution Height) is bottom right corner of screen

Thanks, I got it working, but how can I remove the rectangle when I press enter ? I tried:

but it's not working !

Edited by nordi
##### Share on other sites

just write event handler name after -=

like this:

if (Keys.Enter == e.Key){     this.PerFrameDrawing -= camera_rectangle;}
Edited by ans_ashkan
##### Share on other sites

x and y is for the position on screen, u should calculate x and y, width and height of the rectangle from Game.Resolution in order to position and size the same relative to different resolutions.

the range of x and y is... (0, 0) is top left of the screen and (Resolution Width, Resolution Height) is bottom right corner of screen

Thanks, I got it working, but how can I remove the rectangle when I press enter ? I tried:

if (Keys.Enter == e.Key)                    {                                                this.PerFrameDrawing -= new GraphicsEventHandler(camera_rectangle);                    }

but it's not working !

yeah that is ok though i like to use a bool value to tell my script when an event is hooked so i dont try to unhook when it isnt even hooked, though i dont think it is an issue if u attempt to unhook an event that has not been hooked... i just dont like to allow my script to do that

also the way ans_ashkan wrote i prefer... the c# compiler will know the correct eventhandler object to use and it reads better i think

u probably have some bug in your script that makes u think that the keydown is not working

## Create an account

Register a new account

×