防止窗口从屏幕顶部移动到少于140像素 [英] Preventing a window from moving less than 140 pixels from the top of the screen

查看:55
本文介绍了防止窗口从屏幕顶部移动到少于140像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在VB.net 2010中工作,并且试图防止窗口从屏幕顶部移动到少于140像素.

我正在尝试使用Wndproc,但到目前为止我失败了.

我尝试在以下消息中修改X,Y参数:

具有w_param的WM_SYSCOMMAND SC_MOVE
WM_MOVING
WM_WINDOWPOSCHANGING
WM_GETMINMAXINFO

我还尝试了如下所示的移动",调整大小"和显示"的窗体方法,但是它们导致窗体在鼠标光标位置和我的边界(140px)之间闪烁.

该项目包含多种形式.一种表单固定在屏幕的顶部,高度为140,设置为始终位于顶部(将其称为导航栏).我正试图防止其他表单移动到此导航栏"的后面.

防止表单沿特定方向移动的正确方法是什么?

谢谢!

Hey guys,

I''m working in VB.net 2010, and I''m trying to prevent a window from moving less than 140pixels from the top of the screen.

I''m trying to use Wndproc but so far I''ve failed.

I''ve tried modifiying the X,Y paramaters in the following messages:

WM_SYSCOMMAND with a wparam of SC_MOVE
WM_MOVING
WM_WINDOWPOSCHANGING
WM_GETMINMAXINFO

I''ve also tried using the form methods for Move, Resize, and Shown as suggested below, but they cause the form to flash between the mouse cursor location and my boundary(140px).

The project consists of multiple forms. One form is fixed at the top of the screen with a height of 140, set to always be on top (lets call it the navigation bar). I''m trying to prevent the other forms from being moved behind this "navigation bar".

What is the correct way to prevent a form from moving in a certain direction.

Thanks!

推荐答案

要做您想做的事情,您显然必须使用P/Invoke.这样,您将完全失去平台兼容性.您是否知道您的应用程序,即使是Forms应用程序(但不是WPF),如果编写正确的话,也可以在许多系统上运行而无需重新编译,例如Linux,Mac OS X等?您将要松开它.不用了.

您只需要使用属性Top(或其他属性)并固定位置/大小即可;例如,在事件System.Windows.Forms.Form.Shown的事件处理程序中:
To do what your try to do, you apparently have to use P/Invoke. By doing this, you totally loose platform compatibility. Did you know that your application, even the Forms application (but not WPF) if written accurately, can run on many systems without recompilations, such as Linux, Mac OS X and more? You are going to loose it. No need.

All you need is using the property Top (or whatever) and fixing position/size; for example, in the event handler of the event System.Windows.Forms.Form.Shown:
Me.Shown += Function(sender, eventArgs)
    If Me.Top < 140 Then
        Me.Top = 140
    End If
End Function



这样的事情.除非绝对必要,否则请尝试忘记使用Windows API.您可能会对这种情况很少见感到惊讶.



我同意AspNetDev的观点,AspNetDev提醒我们,这需要向SizeChangedMove之类的事件中添加适当的处理程序.请在下面的评论中查看我们的讨论.

—SA



Something like that. Try to forget about using Windows API unless this is absolutely needed. You probably will be amazed how rarely it is the case.



And I agree with AspNetDev who reminded us that it would require adding appropriate handlers to events like SizeChanged and Move. Please see our discussion in comments below.

—SA


这篇关于防止窗口从屏幕顶部移动到少于140像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆