在不使用FormBorderStyle的情况下无法调整VB.NET中的窗体的大小 [英] Making form in VB.NET unresizable without using FormBorderStyle

查看:88
本文介绍了在不使用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 :)

推荐答案

至少有两种方法:而且我认为,两者都没有实际意义.

#1 :您可以设置Size == MaximumSize == MinimumSize.这种方法的问题:您将能够将鼠标光标置于调整大小区域上,并且光标形状将发生变化,这表明调整大小仍然可以进行.

#2 :您可以使用不可调整大小的边框样式,例如,无边框;在非客户区域将不显示边框;然后您可以绘制模仿可调整大小边框的人工"边框.这种方法的问题:能够注意微小细节的用户将能够看到边缘的工作区靠近标题栏(如果您使用的话)的区别.但是,您在乎吗?

结论:使用不可调整大小的边框样式之一,然后输入有用的内容.有数百万个未解决的问题等待您解决.

—SA
There are at least two approaches; and, in my opinion, both make no practical sense.

#1: you can set Size == MaximumSize == MinimumSize. The problem with this approach: you will be able to position a mouse cursor over the resizing area, and the cursor shape will change, indicating that resizing is still operational, in a trivial way.

#2: you can use the border style which is non-resizeable, for example, no border; it will show no border in the non-client area; and then you can draw an "artificial" border mimicking resizeable border. The problem of this approach: the user who is able to pay attention to tiny detail will be able to see the difference where the client area on the edge is close to the title bar, if you use any. However, do you care?

Conclusion: use one of non-resizeable border styles and go in for something useful. There are millions of unsolved problems which wait you to solve them.

—SA


我终于解决了问题:)
解决方案是重写WndProc-Procedure,并在那里检查WM_NCHITTEST-Message.

我写了一个简短的示例:
I''ve finally solved the problem :)
The solution is to override the WndProc-Procedure and to check for the WM_NCHITTEST-Message there.

I''ve written a short sample:
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中的窗体的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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