VB中如何将光标位置更改为图片框位置

发布于 2024-11-18 08:54:40 字数 398 浏览 6 评论 0原文

我认为标题很清楚,但我会尝试更深入地了解它。

所以我创建了一个用鼠标玩的游戏,就像游戏迷宫一样。你不能碰墙,否则你就输了。

当我启动关卡时,我希望光标出现在它的起始位置,这是一个红色图片框,但我不知道如何...

这是我使用的代码:

Windows.Forms.Cursor.Position = New Point(679 , 650)

正如您所看到的,这段代码存在很大的问题。

光标出现的位置实际上取决于屏幕的分辨率。

例如:对于我的显示器分辨率,位置(679, 650)位于我需要它出现的图片框的顶部。但如果你的显示器上有不同的分辨率,它会出现在不同的地方......

我实际上需要让它出现在图片框的顶部。

我希望我能比这更清楚:(

i think the title is pretty clear but i'll try to get more into it.

so i created a game where you use the mouse to play, it's like the game labirynth. you can't touch the walls or you lose.

when i start the level i want the cursor to appear in it's starting position, which is a red picturebox, but i dont know how to...

here is the code i used:

Windows.Forms.Cursor.Position = New Point(679, 650)

as you can see there is a massive problem about this code.

the location where the cursor appears is actuallt dependent of the resolution of the screen.

for example: with my monitor resolution, the location (679, 650) is right on top of the picturebox i need it to appear on. but if you have a different resolution on your monitor it will appear on a different place...

i need to actually make it appear on top of the picturebox.

i wish i could be clearer than this :(

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

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

发布评论

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

评论(1

迷离° 2024-11-25 08:54:40

您可以在获取图片位置值后设置鼠标位置。

x=picture1.left
y=picture1.top
Windows.Forms.Cursor.Position = New Point(x+somevalue,y+somevalue)

you can set your mouse location after taking the value of your picture position.

x=picture1.left
y=picture1.top
Windows.Forms.Cursor.Position = New Point(x+somevalue,y+somevalue)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文