Results 1 to 11 of 11

Thread: [RESOLVED] Button that calls function to be executed in form_resize

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Resolved [RESOLVED] Button that calls function to be executed in form_resize

    Hello, a very small portion from my form_resize is:
    Code:
    hRgn = CreateRoundRectRgn(0, 0, w, h, 9, 9)
    This (combined with the rest of the code) makes my form have rounded edges, it defines the areas to round off, and the last two variables (9, 9) define the extremity of the curve.

    If I append the following afterwards:
    Code:
    hRgn = CreateRoundRectRgn(0, 0, 230, 145, 9, 9)
    It will make my form 230x145px and then crop the corners to be rounded.

    Presently, I only have the first code implemented, but what I would like to do is have a button, image, whatever on my form that has a click() value that will append the second code to form_resize on it's own.

    Maybe something like the click object enabling a new function in form_resize which has IF commands to it (If enabled, hRgn = CreateRoundRectRgn(0, 0, 230, 145, 9, 9))

    Any ideas how I could do this?

    Hopefully you understand what I mean, if not, just ask and I can try to elaborate.

    By the way, the purpose for this would be to have a button like "Collapse", allowing users to slim down the appearance of the application, hide extra settings, etc...

    David

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

    Re: Button that calls function to be executed in form_resize

    Move your resize code to a private sub on the form then call the sub from the resize event.

    Then, because it is a sub routine, you can also call it from a button click.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Button that calls function to be executed in form_resize

    Since your code really isnt generic it may be tough to place in a procedure for multi use. You could pass the function parameters like the size of the form or something but it may be alot simplier to just place the extra code in the button click event itself. Even if you are duplicating some of the code you wont have to deal with passing size parameters.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Button that calls function to be executed in form_resize

    Perfect! :-) Now my only question, and this is pretty basic, is;

    Now that I have the click event reducing the size, I need a way for them to get it back to 'normal', what can I put into my click event to make another function stating that if the button has been pressed 1 time, to reduce, if its been pressed twice, put back to normal, then if they clicked again it'd go back to 1

    The way I'm explaining it sounds more complicated than it is, I think you'll know what i mean. Basically I just need a 'two-way button'.

    Thanks

  5. #5
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Button that calls function to be executed in form_resize

    I would listen to Rob's suggestion; make a "wider" Function with parameters.

    Then you will be able to call it from anywhere at any time and as you like

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Button that calls function to be executed in form_resize

    That still doesn't solve my problem with the two-way button being needed.

  7. #7
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Button that calls function to be executed in form_resize

    I'm not to familiar with this exact API. On the other hand most APIs allow you to pass different arguments so you can go either way

    A very generic example:
    Code:
    Sub Example(a, b, c)
      'call API from here...
      SomeAPI a, b, c, "other arguments..."
    End Sub
    
    'then call your Sub in one way...
    Example 1, 2, 3
    
    'or go the other...
    Example 3, 2, 1
    Of course, you can also call it directly. It depends if your arguments need any work before calling the API.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Button that calls function to be executed in form_resize

    What I'm looking for is something like this, derived from my current button click event:

    Code:
    Private Sub Image7_Click()
    Dim hRgn As Long, w As Long, h As Long
    
    Dim p(0 To 3) As POINT
    
        w = ScaleX(Me.Width, Me.ScaleMode, vbPixels) - 1
        h = ScaleY(Me.Height, Me.ScaleMode, vbPixels) - 1
        
            hRgn = CreateRoundRectRgn(0, 0, 322, 145, 9, 9) ' on first click, do this
    
    ' code goes here that says if second time clicking, then:
    
            hRgn = CreateRoundRectRgn(0, 0, w, h, 9, 9) ' on second click, do this
            
                Call SetWindowRgn(Me.hwnd, hRgn, True)
        Call DeleteObject(hRgn)
    
    
    End Sub

  9. #9
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Button that calls function to be executed in form_resize

    I would do it with something like this:
    Code:
    Private Sub Command1_Click()
      Static bln As Boolean
      
      bln = Not bln
      
      If bln Then
        'in case bln is True, do one thing...
      Else
        'in case bln is False, do something else...
      End If
    End Sub

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Button that calls function to be executed in form_resize

    Instead of replying upon a boolean variable (multiple fast clicks may throw it out of sync) I would check against the forms size, then adjust it based upon that.

    so if its size is already full then in the click I would have an If Then Else to eval that and enlarge or reduce as eval'd
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Button that calls function to be executed in form_resize

    Good thinking, done, and it works very well.

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