+ Reply to Thread
Results 1 to 9 of 9

Minimize, Maximize in userform

Hybrid View

  1. #1
    Registered User
    Join Date
    11-28-2010
    Location
    egypt
    MS-Off Ver
    Excel 2016
    Posts
    43

    Minimize, Maximize in userform

    hi all
    I want the appearance of the key to Minimize, Maximize in userform
    Minimize key Minimises the above taskbar

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Minimize, Maximize in userform

    Perhaps this is what you are looking for.
    Attached Files Attached Files
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    11-28-2010
    Location
    egypt
    MS-Off Ver
    Excel 2016
    Posts
    43

    Re: Minimize, Maximize in userform

    welcome mikerickson
    thank you very much for your response and help Me
    Benefited a lot of code listed to work

  4. #4
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Minimize, Maximize in userform

    Try this one
    code for module
    Private Const GWL_STYLE As Long = -16
    Public Const MIN_BOX As Long = &H20000
    Public Const MAX_BOX As Long = &H10000
    
    Const SC_CLOSE As Long = &HF060
    Const SC_MAXIMIZE As Long = &HF030
    Const SC_MINIMIZE As Long = &HF020
    Const SC_RESTORE As Long = &HF120
    
    Private Declare PtrSafe Function GetWindowLong _
       Lib "user32.dll" _
        Alias "GetWindowLongA" _
         (ByVal hwnd As Long, _
          ByVal nIndex As Long) As Long
                   
     Private Declare PtrSafe Function SetWindowLong _
      Lib "user32.dll" _
       Alias "SetWindowLongA" _
        (ByVal hwnd As Long, _
         ByVal nIndex As Long, _
         ByVal dwNewLong As Long) As Long
         
    
    Private Declare PtrSafe Function DrawMenuBar _
      Lib "user32.dll" _
       (ByVal hwnd As Long) As Long
    
    
    Private Declare PtrSafe Function GetForegroundWindow _
      Lib "user32.dll" () As Long
    
    Public Sub AddToForm(ByVal Box_Type As Long)
    
    
     Dim BitMask As Long
     Dim Window_Handle As Long
     Dim WindowStyle As Long ' Dim Ret As Long
    
      If Box_Type = MIN_BOX Or Box_Type = MAX_BOX Then
        Window_Handle = GetForegroundWindow()
      
          WindowStyle = GetWindowLong(Window_Handle, GWL_STYLE)
          BitMask = WindowStyle Or Box_Type
      
        Ret = SetWindowLong(Window_Handle, GWL_STYLE, BitMask)
         Ret = DrawMenuBar(Window_Handle)
       End If
    
    End Sub
    and this one add to Userform

    Private Sub UserForm_Activate()
     AddToForm MIN_BOX
     AddToForm MAX_BOX
    End Sub
    Use Code-Tags for showing your code :
    Please mark your question Solved if there has been offered a solution that works fine for you
    If You like solutions provided by anyone, feel free to add reputation using STAR *

  5. #5
    Registered User
    Join Date
    10-19-2017
    Location
    Houston, TX, USA
    MS-Off Ver
    2016
    Posts
    9

    Re: Minimize, Maximize in userform

    Haroon,

    This is very helpful. It works perfectly and still restores the form back to its original size.

    Regards,

  6. #6
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Minimize, Maximize in userform

    For
    for 32 bit version
    remove PtrSafe From Private Function
    Private Declare PtrSafe Function GetWindowLong _

  7. #7
    Registered User
    Join Date
    11-28-2010
    Location
    egypt
    MS-Off Ver
    Excel 2016
    Posts
    43

    Re: Minimize, Maximize in userform

    Thank you HaroonSid
    All right, that's it
    is it possible to preserve the Zoom
    In other words,
    consistent with size of user form and controls

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Minimize, Maximize in userform

    Try this sample
    Private Const MResizer = "ResizeGrab"
    Private WithEvents objResizer As MSForms.Label
    Private LeftResizePos As Single
    Private TopResizePos As Single
    
    Private Sub UserForm_Initialize()
        Set objResizer = Me.Controls.Add("Forms.label.1", MResizer, True)
        With objResizer
            With .Font
                .Name = "Marlett"
            End With
            
            .AutoSize = True
            .Caption = "o"
            .MousePointer = fmMousePointerSizeNWSE
            .ForeColor = RGB(100, 100, 100)
            .ZOrder
            .Top = Me.InsideHeight - .Height
            .Left = Me.InsideWidth - .Width
        End With
    End Sub
    
    Private Sub objResizer_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        If Button = 1 Then
            LeftResizePos = X
            TopResizePos = Y
        End If
    End Sub
    
    Private Sub objResizer_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        On Error Resume Next
        If Button = 1 Then
    
            With objResizer
                .Move .Left + X - LeftResizePos, .Top + Y - TopResizePos
                Me.Width = Me.Width + X - LeftResizePos
    
                Me.Height = Me.Height + Y - TopResizePos
    
                If Me.Width < 250 Then Me.Width = 250
                If Me.Height < 150 Then Me.Height = 150
    
                .Left = Me.InsideWidth - .Width
                .Top = Me.InsideHeight - .Height
            End With
    
            TextBox1.Width = Me.InsideWidth - TextBox1.Left - 20
            SpinButton1.Height = Me.InsideHeight - SpinButton1.Top - 6
        End If
    End Sub
    
    Private Sub CloseBtn_Click()
        Unload Me
    End Sub
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  9. #9
    Forum Contributor HaroonSid's Avatar
    Join Date
    02-28-2014
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    2,095

    Re: Minimize, Maximize in userform

    Welcome AJalal

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to add a Minimize/Maximize Button to a autorun UserForm
    By cshm in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-04-2013, 01:11 PM
  2. Maximize and Minimize the Userform
    By yeshwant_sur in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2012, 06:27 AM
  3. Replies: 4
    Last Post: 09-06-2005, 06:05 AM
  4. Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  5. Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  6. Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  7. Replies: 1
    Last Post: 07-08-2005, 11:05 PM
  8. Replies: 2
    Last Post: 07-08-2005, 11:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1