popopourri
Messages postés2Date d'inscriptiondimanche 23 octobre 2005StatutMembreDernière intervention 9 août 2010
-
13 juil. 2007 à 05:32
popopourri
Messages postés2Date d'inscriptiondimanche 23 octobre 2005StatutMembreDernière intervention 9 août 2010
-
18 juil. 2007 à 06:11
Bonjour , jè aimerais savoir sè il existe un moyen de mettre un fond ( background ) transparent avec un fichier .TXT . Je travail sur un projet avec delphi 6 et lorsque j utilise un fichier texte , exemple pour afficher les paroles d une chanson , lorsque je change la couleur de fond de mon fichier texte , le texte lui-même reste blanc,mais le reste chage de couleur. J aimerais être capable de faire afficher le fond en transparent pour faire plus beau dans mon projet. merci à l avance pour vos conseils . À bientôt.
Rénald ( mirega@videotron.ca ) ..
japee
Messages postés1727Date d'inscriptionvendredi 27 décembre 2002StatutModérateurDernière intervention 6 novembre 20218 13 juil. 2007 à 13:56
Salut,
Tu peux afficher ton texte dans un TLabel dont tu règles les propriétés "Transparent", "Autosize" et "WordWrap" à True.
Tu peux également, selon la longueur du texte, placer ton Label dans une ScrollBox.
Le plus délicat étant, si tu charges un fichier en cours d'exécution, de déterminer à quel moment régler ces valeur. Voici un exemple simple en placant un label dans une SrollBox qui charge un fichier texte dans le TLabel :
procedure TForm1.FormCreate(Sender: TObject);
const
SB_WIDTH = 22; // estimation approximative...
FOREGROUND_COLOR = $00C080FF;
TEXT_FONT_COLOR = clWhite;
begin
ScrollBox1.Color := FOREGROUND_COLOR;
ScrollBox1.Font.Color := TEXT_FONT_COLOR;
ScrollBox1.VertScrollBar.Tracking := True;
with Label1 do
begin
Autosize := False;
Transparent := True;
end;
with TStringList.Create do
try
LoadFromFile('Fichier.txt');
with Label1 do
begin
Caption := Text;
AutoSize := True;
Width := ScrollBox1.Width - SB_WIDTH;
WordWrap := True;
end;
finally;
Free;
end;
end;
Bien sûr c'est du "vite fait", et il y aurait sans doute intérêt à faire une ou plusieurs fonctions avec ce code afin de faciliter son utilisation, surtout s'il faut charger des fichiers différents en cours d'exécution du programme.
japee
Messages postés1727Date d'inscriptionvendredi 27 décembre 2002StatutModérateurDernière intervention 6 novembre 20218 13 juil. 2007 à 19:59
Je viens de revoir mon code précédent...
On a toujours un Label dans une ScrollBox, et on peut charger un fichier *.txt avec un Opendialog et un Button, en appelant la procedure LoadText.
Là c'est plus propre :
procedure TForm1.LoadText(const FileName: string);
begin
with TStringList.Create do
try
LoadFromFile(FileName);
with Label1 do
begin
Caption := Text;
Width := ScrollBox1.Width - SB_WIDTH;
WordWrap := True;
end;
finally;
Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Color := FOREGROUND_COLOR;
ScrollBox1.Color := FOREGROUND_COLOR;
ScrollBox1.Font.Color := TEXT_FONT_COLOR;
{ les 3 lignes suivantes peuvent être réglées dans l'inspecteur d'objets }
ScrollBox1.VertScrollBar.Tracking := True; // facultatif
Label1.Transparent := True;
Label1.AutoSize := True;
LoadText('Fichier.txt');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
LoadText(OpenDialog1.FileName);
end;
popopourri
Messages postés2Date d'inscriptiondimanche 23 octobre 2005StatutMembreDernière intervention 9 août 2010 18 juil. 2007 à 06:11
Bonsoir , cela ne répond pas exactement a ma question.. je suis débutant et peut-être un peu lent a comprendre. Voici un appercu de ce que je veux parler..
______________________________________________________________
unit U2FORM2;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
VAR TOUNE : STRING;
VAR NB : INTEGER;
implementation
{$R *.dfm}
procedure TForm2.Label1Click(Sender: TObject);
begin
TOUNE := LABEL1.CAPTION + 'THE JOSHUA TREE';
MEDIAPLAYER1.FileName := TOUNE;
MEDIAPLAYER1.Open;
progressbar1.Max := mediaplayer1.Length;
listbox1.Clear;
IF LABEL1.Caption = 'THE JOSHUA TREE' THEN
IF LABEL3.Caption = '1 - WHERE THE STREETS HAVE NO NAME' THEN
LISTBOX1.Items.LoadFromFile('1 - WHERE THE STREETS HAVE NO NAME.TXT');
end;
procedure TForm2.Label2Click(Sender: TObject);
begin
TOUNE := LABEL2.CAPTION + '.WMA';
MEDIAPLAYER1.FileName := TOUNE;
NB:=2;
MEDIAPLAYER1.Open;
progressbar1.Max := mediaplayer1.Length;
IF LABEL2.Caption = '2 - I STILL HAVENT FOUND WHAT IM LOOKING FOR' THEN
LISTBOX1.Items.LoadFromFile('2 - I STILL HAVENT FOUND WHAT IM LOOKING FOR.TXT');
end;
procedure TForm2.Label3Click(Sender: TObject);
begin
TOUNE := LABEL3.CAPTION + '.WMA';
MEDIAPLAYER1.FileName := TOUNE;
NB :=3;
MEDIAPLAYER1.Open;
progressbar1.Max := mediaplayer1.Length;
IF LABEL4.Caption = '3 - WITH OR WITHOUT YOU' THEN
LISTBOX1.Items.LoadFromFile('3 - WITH OR WITHOUT YOU.TXT');
end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
if progressbar1.Max<>0 then
progressbar1.Position := mediaplayer1.Position;
end;
procedure TForm2.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
begin
PROGRESSBAR1.POSITION := 0;
END;
procedure TForm2.FormCreate(Sender: TObject);
begin
PROGRESSBAR1.POSITION := 0;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
FORM2.Close;
end;
end.
En gros cela regarde comme ça , pouvez-vous m aider ???? .
dans mon TForm1 , j ai 2 images avec chacun un label en dessous et un bouton qui ferme le projet.
Lorsque je click sur une image cela transfert dans le TForm2 qui elle affiche a nouveau l image que j ai clické dessus et la chanson que je veux entendre, lorsque je click sur le titre de la chanson , les paroles s afficher dans le listbox, mais avec un backgroud blanc. ( c est ça mon problème )
_______________________________________________________________
unit U2FORM1;
procedure TForm1.Image2Click(Sender: TObject);
begin
FORM2.CAPTION := 'U2 - THE JOSHUA TREE';
FORM2.Image1.Picture.LoadFromFile('JOSHUA.JPG');
FORM2.Label1.Caption := 'THE JOSHUA TREE';
FORM2.Label2.CAPTION := '1 - ONE';
FORM2.Label3.Caption := '';
FORM2.Label4.Caption := '';
FORM2.SHOW;
end;
procedure TForm1.Image3Click(Sender: TObject);
begin
FORM2.CAPTION := 'U2 - THE JOSHUA TREE';
FORM2.Image1.Picture.LoadFromFile('ACHTUNG.JPG');
FORM2.Label1.Caption := 'ACHTUNG BABY';
FORM2.Label2.CAPTION := '1 - I STILL HAVENT FOUND WHAT IM LOOKING FOR';
FORM2.Label3.Caption := '2 - WITH OR WITHOUT YOU';
FORM2.Label4.Caption := '3 - WHERE THE STREETS HAVE NO NAME';
FORM2.SHOW;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
APPLICATION.Terminate;
end;
end.
Voici en gros mon projet....