I have a project with one FadeIn Timer and One FadeOut Timer. My form is created by FadeIn Timer and is closed by FadeOut Timer. Initially FadeIn Timer is enabled and FadeOut Timer is disabled. FadeIn Timer Code :
if MainForm.AlphaBlendValue >= 235 then
Timer01.Enabled := false
else
MainForm.AlphaBlendValue := MainForm.AlphaBlendValue + 5;
FadeOut Timer Code :
if MainForm.AlphaBlendValue <= 0 then
Timer02.Enabled := false
else
MainForm.AlphaBlendValue := MainForm.AlphaBlendValue - 5;
close;
My requirement is that the FadeOut Timer will be active if I click on the “X” Button of the Caption Bar. So I defined
if Msg.Result=htClose then
FadeOutTimer.Enabled:=true;
But it not working. Please help me.
If the form just closes immediately, then you need a global form variable like
FAllowClosethat you set toFalsewhen the form is created. Then you need to write code for theForm.CloseQueryevent. Something simple like this should work:<<< 2012/07/17 Edit >>>
When the user clicks the “X” button on the form, the only one way to stop the form from closing is to cancel it in the
OnCloseQueryevent. Then when you are done fading out the form, you close the form. You’ll need a global variable likeFAllowCloseto signal theOnCloseQueryevent that you are close the form instead of the user. This code is a little more illustrative, and should handle the situation where a user clicks the “X” again while it is fading out.