Xna - 获取窗口位置?

发布于 2024-09-16 01:10:23 字数 119 浏览 4 评论 0原文

我正在尝试安装 XNA WinForms 系统,这样我就可以拥有一个游戏编辑器,并且我需要使用鼠标。由于 XNA 鼠标输入类根据窗口位置报告鼠标位置,因此我需要将表单放置在同一位置。我如何获取 XNA 游戏使用的窗口的位置?

I'm trying to rig an XNA WinForms system so I can have a game editor, and I need to use the mouse for it. Since the XNA Mouse input class reports mouse position based off of the window's location, I need to place the form I have in the same spot. How can i get the location of the window that my XNA game uses?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瑾兮 2024-09-23 01:10:23

我最终用这段代码做到了:

        Form gameWindowForm = (Form)Form.FromHandle(this.Window.Handle);
        ...
        myForm.Location = new System.Drawing.Point(gameWindowForm.Location.X - 5,gameWindowForm.Location.Y - 5); //-5 pixels for adjustment

效果很好!

I ended up doing it with this code:

        Form gameWindowForm = (Form)Form.FromHandle(this.Window.Handle);
        ...
        myForm.Location = new System.Drawing.Point(gameWindowForm.Location.X - 5,gameWindowForm.Location.Y - 5); //-5 pixels for adjustment

which works just dandy!

迷鸟归林 2024-09-23 01:10:23

Game.Window.ClientBounds 结构的 X 和 Y 属性应该为您提供所需的绝对窗口坐标。

The X and Y properties of the Game.Window.ClientBounds struct should give you the absolute window coordinates you're looking for.

夏日落 2024-09-23 01:10:23

我的关卡编辑器也遇到了这个问题。我的 Windows 窗体中有一个图片框,因此初始化 XNA 游戏时我唯一需要做的就是:

Mouse.WindowHandle = this.windowForm.Viewport.Handle;

其中 Viewport 是图片框,

现在 XNA 鼠标位置会自动正确调整。

I encountered this problem too with my level editor. I have a picturebox in my windows Forms, so the only thing i needed to to when initializing the XNA game:

Mouse.WindowHandle = this.windowForm.Viewport.Handle;

where Viewport is the picturebox

now the XNA mouse position is adjusted properly automatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文