VB怎么控制窗口大小,只能让他保持这么大?
将窗口的BorderStyle属性设置为Fixed Single即可,如果还需要最小化按钮,将MinButton属性设置为True。
另外,楼上说的SetWindowPos完全不是用来限制窗口大小的,它只是用来设置窗口大小、位置和Z序等而已。
如果要通过其他方法限制窗口大小,可以通过响应WM_GETMINMAXINFO消息来实现(这需要替换窗口过程)
以下内容来自MSDN:
WM_GETMINMAXINFO
The WM_GETMINMAXINFO message is sent to a window when the size or
position of the window is about to change. An application can use this message
to override the window's default maximized size and position, or its default
minimum or maximum tracking size.
A window receives this message through its WindowProc function.
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_GETMINMAXINFO
WPARAM wParam, // not used
LPARAM lParam // window information (LPMINMAXINFO)
);
Parameters
wParam
This parameter is not used.
lParam
Pointer to a MINMAXINFO structure that
contains the default maximized position and dimensions, and the default minimum
and maximum tracking sizes. An application can override the defaults by setting
the members of this structure.
您好,您可以使用下面的代码实现:
'在窗体全局声明中加入:
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const SWP_NOSIZE = &H1
'……
'在form_load里面写以下代码:
SetWindowPos ,me.Hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE
如果本次回答对您有帮助,请您采纳以支持我们的发展,谢谢 !!