| View previous topic :: View next topic |
| Author |
Message |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sat Nov 10, 2007 6:32 pm Post subject: Fade In/Fade out Function?(Delphi) |
|
|
| How would I be able to do a Fade in and Fade out function for a project. I've seen it done many times, I've asked SCRN how he does it but he hasn't sent a reply. I would appreciate if someone can teach me how to do it in Delphi. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Nov 10, 2007 7:47 pm Post subject: |
|
|
| Code: |
procedure/function/whatever...
:
var
:
i : integer;
:
begin
:
:
//Fade in
for i := 0 to 100 do
MyForm.Opacity := i; //I think that's how you do it--not quite sure about the Form.Opacity: it's how you'd do it in C#
:
:
//Fade out
for i:= 100 to 0 do
MyForm.Opacity := i;
:
:
end
|
|
|
| Back to top |
|
 |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sat Nov 10, 2007 8:07 pm Post subject: |
|
|
| I already got I just need to know how to make it fade out when you close the form. |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Nov 10, 2007 8:35 pm Post subject: |
|
|
| Destructor |
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Sun Nov 11, 2007 12:44 am Post subject: |
|
|
| samuri25404 wrote: | | Code: |
//Fade out
for i:= 100 to 0 do
MyForm.Opacity := i;
|
|
It will not work in delphi. In delphi u need to do it like this
| Code: | for i:= 100 Down to 0 do
MyForm.Opacity := i; |
ehe is my code:
| Code: | repeat
//In
AlphaBlendValue:=AlphaBlendValue+1;
until AlphaBlendValue = 255;
//Out
repeat
AlphaBlendValue:=AlphaBlendValue-1;
until AlphaBlendValue = 0; |
make sure that "AlphaBlend" in Object Inspector is "True". |
|
| Back to top |
|
 |
Never Again I post too much
Reputation: 0
Joined: 13 Jan 2007 Posts: 2000 Location: New Mexico
|
Posted: Sun Nov 11, 2007 1:17 am Post subject: |
|
|
Nevermind, thanks anyways I found it out already.
| Code: | --------
Fade in:
Code:
--------
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Form1.AlphaBlendValue >= 255 then
begin
Timer1.Enabled := false;
end
else
begin
Form1.AlphaBlendValue := Form1.AlphaBlendValue + 5;
end;
end;
---------
Fade out:
Code:
---------
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Form1.AlphaBlendValue <= 0 then
begin
Timer1.Enabled := false;
end
else
begin
Form1.AlphaBlendValue := Form1.AlphaBlendValue - 5;
end;
end; |
|
|
| Back to top |
|
 |
Uzeil Moderator
Reputation: 6
Joined: 21 Oct 2006 Posts: 2411
|
Posted: Sun Nov 11, 2007 2:29 am Post subject: |
|
|
Or writen with the assumption that you want it to fade in when opening the application, and out when closing:
(Poorly coded, I didn't feel like finding a better event to code it in, so I just had another thread do it.)
| Code: | type mythread = class(TThread)
public
procedure execute; override;
end; |
| Code: | procedure TForm1.FormShow(Sender: TObject);
begin
alphablendvalue:=0;
mythread.Create(false);
end;
procedure mythread.execute;
var i: integer;
begin
for i:=0 to 255 do
Form1.AlphaBlendValue:=i;
terminate;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var i: integer;
begin
for i:=255 downto 0 do
Form1.AlphaBlendValue:=i;
end; |
Although personally, I don't like fading out... I like my programs to close immediately upon hitting the big [X]. _________________
|
|
| Back to top |
|
 |
|