[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
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.
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.
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
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 ;)
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.
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.
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
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
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
Re: Button that calls function to be executed in form_resize
Good thinking, done, and it works very well.