Results 1 to 3 of 3

Thread: VB - Flexible Shangle (window resizing grip)

  1. #1

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    VB - Flexible Shangle (window resizing grip)

    The resizing grip in the corner of a window is called a shangle (supposedly a combination of shingle and triangle).

    This code is a sample of how to create your own.

    I have used a couple of labels to draw the graphic for the shangle, but I guess you could another control and have a shangle of any size/color/design you wanted, perhaps the nifty XP one with dots instead of diagonal lines. Code could also be modified to put the shangel somewhere other than in the corner. A pull-down handle perhaps, or at the bottom left, for RightToLeft forms.

    Code is a bit of a cludge (hate that timer for instance) and I'm sure somebody with more time than me can easily improve it.

    Mail me if you post a better one and I'll delete this post.


    Here's module1.bas

    VB Code:
    1. Option Explicit
    2.  
    3.  
    4.  
    5. Declare Function ReleaseCapture Lib "user32" () As Long
    6. Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    7.  
    8.  
    9.        
    10. Public Const WM_NCLBUTTONDOWN = &HA1
    11. Public Const HTBOTTOMRIGHT = 17
    12. Sub DriveShangle(f As Form)
    13.   'PURPOSE: Negate VB's call to SetCapture, and tell Windows
    14.   '         that the user is trying to resize the form.
    15.    
    16.    ReleaseCapture
    17.    SendMessage f.hwnd, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, ByVal 0&
    18.  
    19. End Sub
    20. Sub FixShangle(f As Form)
    21.    
    22.   'PURPOSE: Position size grip labels at lower-right.
    23.  
    24.   With f.labShangle(0)
    25.     .Move .Container.ScaleWidth - .Width, .Container.ScaleHeight - .Height
    26.   End With
    27.   With f.labShangle(1)
    28.     .Move .Container.ScaleWidth - .Width, .Container.ScaleHeight - .Height
    29.   End With
    30.   If f.WindowState = vbNormal Then
    31.     f.labShangle(0).Visible = True
    32.     f.labShangle(1).Visible = True
    33.     f.timShangle.Enabled = Not f.timShangle.Enabled
    34.   Else
    35.     f.labShangle(0).Visible = False
    36.     f.labShangle(1).Visible = False
    37.     f.timShangle.Enabled = False
    38.   End If
    39. End Sub

    here's form 1. Needs a couple of labels in an array and a timer, as you can see.

    VB Code:
    1. Option Explicit
    2.  
    3.  
    4. Private Sub Form_Resize()
    5.   FixShangle Me 'Position the Shangle
    6. End Sub
    7.  
    8. Private Sub labShangle_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    9.   DriveShangle Me 'Do window resizing with the Shangle
    10.  
    11. End Sub
    12.  
    13. Private Sub timShangle_Timer()
    14.   FixShangle Me 'Redraw the Shange after a normalise event
    15. End Sub
    Attached Files Attached Files
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

  2. #2
    Fanatic Member
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    635
    Your code works well. But here is a better example:
    http://www.mvps.org/vbnet/code/forms/fakesizegrip.htm . Also this link's code creates a more realistic resize grip effect.
    A.A. Fussy
    Babya Software Group

  3. #3

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796
    Originally posted by aafuss
    Your code works well. But here is a better example:
    http://www.mvps.org/vbnet/code/forms/fakesizegrip.htm . Also this link's code creates a more realistic resize grip effect.
    Why is it better?

    I grant you the code is tidier and mine is a kludge thrown together in a hurry as I said, but:

    1) The shangle does not disappear when you maximize the form.

    2) The code resides on the form itself, so if you have a lot of forms you repeat the code over and over.

    3) Why is the grip 'more realistic'? Looks pretty much the same to me - although you can have any grip you like in either set of code with a few trivial alterations.

    What it really needs is somebody with a bit of time to write a drop-in control.
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width