Results 1 to 8 of 8

Thread: [RESOLVED] Commandbutton to make form border invisible?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Resolved [RESOLVED] Commandbutton to make form border invisible?

    I want to make the border on a form invisible on the click of a command button, like msn live messenger does on the conversations windows. Any ideas?

    Stevevb6
    Last edited by Hack; Mar 30th, 2007 at 05:47 AM. Reason: Added [RESOLVED] to thread title and green "resolved" checkmark

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Commandbutton to make form border invisible?

    This should work for you (I think -- no copy of VB installed at the moment so I can't check if the property name is BorderStyle or not). I believe 0 is the value you're looking for -- but it could be 1 or 2. Look at the form's possible values for the BorderStyle property to find out which one it should be if this doesn't work for you. You'll be looking for the value titled "No border," or something similar.
    vb Code:
    1. Private Sub Command1_Click()
    2.   Me.BorderStyle = 0
    3. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Re: Commandbutton to make form border invisible?

    i have tried that, i figured it would work but it does nothing...

  4. #4
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Commandbutton to make form border invisible?

    Code:
    Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    
    Private Sub Form_DblClick()
        Unload Me
    End Sub
    
    Private Sub Form_Load()
        Dim WinRectRgn As Long
        Dim WinRndRectRgn As Long
        
        'VB APIs work in pixels
        Me.ScaleMode = vbPixels
        'Cause i'm going to write something on the form
        Me.AutoRedraw = True
        'Me message
        Me.Print "Double click to close form"
        
        'Make a normal rectangular window - left, top, width, height
        WinRectRgn = CreateRectRgn(5, 30, Me.ScaleWidth - 5, Me.ScaleHeight - 5)
        'Make a rectangular window with rounded corners - left, top, width, height, X roundness, Y roundness
        WinRndRectRgn = CreateRoundRectRgn(5, 30, Me.ScaleWidth - 5, Me.ScaleHeight - 5, 30, 30)
        
        'Set the window region
        'Comment as required
        
        SetWindowRgn Me.hWnd, WinRectRgn, True  'Normal rectangle
        'SetWindowRgn Me.hWnd, WinRndRectRgn, True   'Round rectangle
        
    End Sub
    You can also make the form round or have custom regions as required

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Commandbutton to make form border invisible?

    I installed VB and tried it for myself. I guess you can't change the border properties after the form is initialized -- at least not without the use of an API, maybe. if you really want this, you could always make a clone of the look of the window menu naturally and then make a border-less form that just resized when pressing a button. if you built the program using Windows XP and ran it under Vista it would have a graphical menu that looked like it was from Windows XP, though.. so that method doesn't offer much flexibility. sorry, I can't really help you much here.

    edit: I don't think the code posted above is exactly what you want, but after looking through it, I guess it might work. doesn't look very nice in Vista after redrawing the form and putting it back to the normal vista-ish look.
    Last edited by kows; Mar 27th, 2007 at 12:07 AM.

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Commandbutton to make form border invisible?

    check out Karl E Peterson's FormBdr example

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Commandbutton to make form border invisible?

    True this
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    4. (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    5.  
    6. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    7. (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    8.  
    9. Private Declare Function SetWindowPos Lib "user32" _
    10. (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
    11. ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    12.  
    13. Private Const WS_CAPTION = &HC00000
    14. Private Const GWL_STYLE = (-16)
    15. Private Const SWP_FRAMECHANGED = &H20
    16. Private Const SWP_NOMOVE = &H2
    17. Private Const SWP_NOSIZE = &H1
    18. Private Const SWP_NOZORDER = &H4
    19.  
    20. Private Function DisplayCaption(ByVal IsDisplayed As Boolean) As Boolean
    21.         Dim MyStyle As Long
    22.        
    23.         MyStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
    24.           If IsDisplayed Then
    25.              MyStyle = MyStyle Or WS_CAPTION
    26.           Else
    27.              MyStyle = MyStyle And Not WS_CAPTION
    28.           End If
    29.          
    30.           If SetWindowLong(Me.hwnd, GWL_STYLE, MyStyle) Then
    31.              If MyStyle = GetWindowLong(Me.hwnd, GWL_STYLE) Then
    32.                 DisplayCaption = True
    33.              End If
    34.          End If
    35.          
    36.          SetWindowPos hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_NOSIZE
    37. End Function
    38.  
    39. Private Sub Form_Load()
    40. DisplayCaption False
    41. End Sub
    42.  
    43. Private Sub Command1_Click()
    44. DisplayCaption True
    45. End Sub

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    93

    Re: Commandbutton to make form border invisible?

    that works, thanks!

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