本文介绍了在不使用FormBorderStyle的情况下无法调整VB.NET中的窗体的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我注意到,即使Windows 7的边框看起来像可调整大小的窗体,它也无法调整大小.
我测试了将``FormBorderStyle''设置为``Fixed'',但是将ControlBox-Property设置为``false''根本不会出现任何边框.

顺便说一句:打开混音器"将出现另一种形式,该高度不能更改.
当然,我可以使用MinSize/MaxSize属性来实现这种效果,但是与Windows窗体不同,当我尝试调整窗体大小时,仍会显示可调整大小的光标.

那么,您对如何使窗体的行为类似于声级控制窗口有任何想法吗?

PS:抱歉,英语:)

Hi all!
I have noticed that the form used to control the sound level in Windows 7 isn''t resizable, even though it has got a border looking like a resizable one.
I tested setting ''FormBorderStyle'' to ''Fixed'', but with the ControlBox-Property set to ''false'' there won''t appear any border at all.

Btw: By opening ''Mixer'' another form will appear, which hight cannot be changed.
Of course I could use MinSize/MaxSize properties to achieve such an effect, but unlike in the Windows-Form a resizable-cursor is still being shown when I try to resize the form.

So do you have any ideas of how to make a form behave similarly to the sound-level control window?

PS: sorry for english :)

推荐答案


Public Class Form1

    Public Const WM_NCHITTEST As Integer = &H84

    Dim _FixedState As FixedState = FixedState.Horizontal
    
    Enum FixedState As Integer
        None = 0
        Horizontal = 1
        Vertical = 2
        Both = 3
    End Enum

    Enum HitTest As Integer
        Caption = 2
        Transparent = -1
        Nowhere = 0
        Client = 1
        Left = 10
        Right = 11
        Top = 12
        TopLeft = 13
        TopRight = 14
        Bottom = 15
        BottomLeft = 16
        BottomRight = 17
        Border = 18
    End Enum

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        MyBase.WndProc(m)

        If m.Msg <> WM_NCHITTEST Or _FixedState = FixedState.None Then Return

        If _FixedState = FixedState.Both Then
            m.Result = New IntPtr(HitTest.Nowhere)
        Else
            Select Case m.Result.ToInt32
                Case HitTest.Top, HitTest.Bottom
                    If _FixedState = FixedState.Vertical Then m.Result = New IntPtr(HitTest.Nowhere)
                Case HitTest.Left, HitTest.Right
                    If _FixedState = FixedState.Horizontal Then m.Result = New IntPtr(HitTest.Nowhere)
                Case HitTest.TopLeft
                    m.Result = New IntPtr(CInt(IIf(_FixedState = FixedState.Horizontal, HitTest.Top, HitTest.Left)))
                Case HitTest.TopRight
                    m.Result = New IntPtr(CInt(IIf(_FixedState = FixedState.Horizontal, HitTest.Top, HitTest.Right)))
                Case HitTest.BottomLeft
                    m.Result = New IntPtr(CInt(IIf(_FixedState = FixedState.Horizontal, HitTest.Bottom, HitTest.Left)))
                Case HitTest.BottomRight
                    m.Result = New IntPtr(CInt(IIf(_FixedState = FixedState.Horizontal, HitTest.Bottom, HitTest.Right)))
            End Select
        End If
    End Sub

End Class


可以在此处查找枚举"HitTest" .

变量_FixedState设置宽度/高度还是两个属性都是固定的.

对我来说效果很好:D

此致Kai


The enumeration ''HitTest'' can be looked up here.

The variable _FixedState sets whether the width/height or both properties are fixed.

For me it works quite well :D

Regards, Kai


这篇关于在不使用FormBorderStyle的情况下无法调整VB.NET中的窗体的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 23:41