Jump to content
  • Advertisement
Sign in to follow this  
gabzuka

[.net] Trouble with points and windows

This topic is 4195 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys/gals: I build a simple test program in VC# 2005 that's just a window that tells me my mouse position and the window size, the thing is that if I move my mouse to the edge of the window the window size and the mouse position are different in this example case I have mouse pos 426 and window height 423. Is this something to do with different coordinate systems or something? ... To get the mouse position on the mouse move event I do:

private void Graficador_MouseMove(object sender, MouseEventArgs e)
{
    x = e.X.ToString();
    y = label2.Text = e.Y.ToString();
}

to get the window size I do:

private void Graficador_Load(object sender, EventArgs e)
{
    h = this.Height;
    w = this.Width;
}

Thanks in advance, G

Share this post


Link to post
Share on other sites
Advertisement
Hey - not sure exactly what the problem is... at least I won't be until I can investigate it a bit more, but try using Me.ClientSize inside of Me.Size (which includes Me.Width/Me.Height). This only provides the client area, not including the border.
Hope that helps.

Share this post


Link to post
Share on other sites
well, that solved it! ... not sure why but using ClientSize gives me the right value ... any ideas on why this.Width is different than this.ClientSize.Width?

thanks alex_myrpg!

Share this post


Link to post
Share on other sites
Yes, they're different coordinate systems. Windows have to interact with screen coordinates and client coordinates. See MSDN: Window Coordinate System and About Windows.

In screen coordinates, point (0, 0) corresponds to the top-left corner of the primary screen (on multimon this means secondary monitors can have negative coordinates).

In client coordinates, point (0, 0) corresponds to the top-left corner of the client rectangle of a window. The client rectangle is smaller than the total window rectangle in most cases, and typically excludes stuff like the window frame, menu bar, status bar, and other docked bars. You can create windows without borders and titlebar, in which case the client rectangle will have the same size as the window rectangle.

The coordinates for MouseMove, MouseClick, etc. are in client coordinates.

Hopefully this diagram helps:

Share this post


Link to post
Share on other sites
No problem. mutex has a good explanation of *why* this is so too. Although I am a bit confused why you have mous pos > width rather than < width. Oh well, at least you know the use of ClientSize now. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!