Click here to Skip to main content
15,891,900 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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 :)
Posted
Comments
Sergey Alexandrovich Kryukov 18-Oct-12 18:36pm    
Well, you can see it if you position the mouse cursor over the edge, so it will go into the resizing area. Do you see the change in cursor shape? If you see, this is the case.
--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
 
Share this answer
 
v2
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

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900