Projet avec delphi 6

popopourri Messages postés 2 Date d'inscription dimanche 23 octobre 2005 Statut Membre Dernière intervention 9 août 2010 - 13 juil. 2007 à 05:32
popopourri Messages postés 2 Date d'inscription dimanche 23 octobre 2005 Statut Membre Derniè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 ) ..

3 réponses

japee Messages postés 1727 Date d'inscription vendredi 27 décembre 2002 Statut Modérateur Dernière intervention 6 novembre 2021 8
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.

Bonne prog'
0
japee Messages postés 1727 Date d'inscription vendredi 27 décembre 2002 Statut Modérateur Dernière intervention 6 novembre 2021 8
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 :

const
  SB_WIDTH = 22; // estimation approximative...
  FOREGROUND_COLOR = $008080FF;
  TEXT_FONT_COLOR = clWhite;

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;

Bonne prog'
0
popopourri Messages postés 2 Date d'inscription dimanche 23 octobre 2005 Statut Membre Derniè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;


interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, MPlayer, StdCtrls, ComCtrls, Gauges;


type
  TForm2 = class(TForm)
    Image1: TImage;
    MediaPlayer1: TMediaPlayer;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    ProgressBar1: TProgressBar;
    ListBox1: TListBox;
    Button1: TButton;
    Label3: TLabel;
    Label4: TLabel;
    procedure Label1Click(Sender: TObject);
    procedure Label2Click(Sender: TObject);
    procedure Label3Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
      var DoDefault: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);


  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;


interface


uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, jpeg, ExtCtrls, StdCtrls;


type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    procedure Image2Click(Sender: TObject);
    procedure Image3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;


implementation


uses U2FORM2;


{$R *.dfm}


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....
0
Rejoignez-nous