IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Delphi Discussion :

impression d'un memo


Sujet :

Delphi

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2012
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Septembre 2012
    Messages : 10
    Points : 5
    Points
    5
    Par défaut impression d'un memo
    bonjour tous le monde, bon voila mon pb: j'ai une fiche qui contient un memo qui est sauvegardé dans un dossier (contrat.txt) je veut imprimer ce doc ou le contenu de ce memo en cliquant sur un bouton. j'aimerai bien avoir de l'aide. merci d'avance.

  2. #2
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 858
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Biologiste ; Progr(amateur)

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 858
    Points : 11 302
    Points
    11 302
    Billets dans le blog
    6
    Par défaut
    Style ShellExec('Print', 'Contrat.txt', nil, nil, ...) en syntaxe approximative ?
    Delphi 5 Pro - Delphi 11.3 Alexandria Community Edition - CodeTyphon 6.90 sous Windows 10 ; CT 6.40 sous Ubuntu 18.04 (VM)
    . Ignorer la FAQ Delphi et les Cours et Tutoriels Delphi nuit gravement à notre code !

  3. #3
    Membre régulier
    Homme Profil pro
    Inscrit en
    Août 2006
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2006
    Messages : 108
    Points : 82
    Points
    82
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    https://www.google.fr/search?q=delphi+print+memo&oq=delphi+print+memo&sugexp=chrome,mod=5&sourceid=chrome&ie=UTF-8
    Beny

  4. #4
    Membre expert
    Avatar de Charly910
    Homme Profil pro
    Ingénieur TP
    Inscrit en
    Décembre 2006
    Messages
    2 346
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur TP
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Décembre 2006
    Messages : 2 346
    Points : 3 124
    Points
    3 124
    Par défaut
    Bonjour,

    sinon autre méthode : tu peux imprimer Contrat.txt en passant par NotePad, ce qui permet à l'utilisateur de le modifier avant impression s'il le souhaite

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    uses ShellAPI;
    ...
    var 
       Chemin, Fichier : String;
    ...
       Chemin  :='C:\MonChemin\' ;
       Fichier :='Contrat.txt'  
       ShellExecute(Handle,'Open',PChar('C:\Windows\Notepad.exe'),PChar(Chemin+Fichier),Nil,SW_SHOWDEFAULT);
    A+

    Charly

  5. #5
    Futur Membre du Club
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2012
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Septembre 2012
    Messages : 10
    Points : 5
    Points
    5
    Par défaut
    merci bcp

  6. #6
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 427
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 427
    Points : 1 326
    Points
    1 326
    Par défaut
    Bonjour à toutes et à tous,

    @ samiafares, dans le cas ou ton mémo serait trop long et ainsi éviter d'utiliser deux pages, tu pourrais l'imprimer sur une page mais sur deux colonnes !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
     
    implementation
     
    {$R *.dfm}
     
    uses printers,ComCtrls, RichEdit,Types;
     
     
    function PrintRTFToCanvas(ACanvas : TCanvas; FromChar, ToChar : integer;
                          ARichEdit : TRichEdit; var ARect : TRect;RenderIt:boolean) : Longint;
    var  Range    : TFormatRange;
    begin
        //Précaution
        SendMessage(ARichedit.Handle, EM_FORMATRANGE, 0, 0);
     
        if not RenderIt then
        begin
          SetRect(ARect,0,0,ARichEdit.Width,ARichEdit.Height);
        end;
     
        FillChar(Range, SizeOf(TFormatRange), 0);
        Range.hdc        := ACanvas.handle;
        Range.hdcTarget  := ACanvas.Handle;
        Range.rc.left    := ARect.Left * 1440 div ACanvas.font.PixelsPerInch;
        Range.rc.top     := Arect.Top * 1440 div ACanvas.font.PixelsPerInch;
        Range.rc.right   := ARect.Right * 1440 div ACanvas.font.PixelsPerInch;
        Range.rc.Bottom  := ARect.Bottom * 1440 div ACanvas.font.PixelsPerInch;
        Range.chrg.cpMax := ToChar;
        Range.chrg.cpMin := FromChar;
        if RenderIt
        then Result := SendMessage(ARichedit.Handle, EM_FORMATRANGE, 1, Longint(@Range))
        else begin
               Range.chrg.cpMax := ARichedit.GetTextLen;
               Result := SendMessage(ARichedit.Handle, EM_FORMATRANGE, 0, Longint(@Range));
               ARect:=Range.rc;
               ARect.Bottom  := Range.rc.Bottom * Screen.PixelsPerInch div 1440;
             end;
       SendMessage(ARichEdit.handle, EM_FORMATRANGE, 0,0);
    end;
     
    function PrintTextToCanvas(ACanvas : TCanvas; FromChar, ToChar : integer;
                          Text : TStrings; var ARect : TRect;RenderIt:boolean) : Longint;
    var ARichEdit:TRichEdit;
        AHandle:HWND;
        RelRect:TRect;
    begin
     
      ARichEdit:=TRichEdit.Create(nil);
      try
      finally
        ARichEdit.Visible := False;
        ARichEdit.Parent := Application.MainForm;
     
        ARichEdit.Width:=round((ARect.Right-ARect.Left)*ARichEdit.Font.PixelsPerInch/ACanvas.Font.PixelsPerInch);
        ARichEdit.Height:=round((ARect.Bottom-ARect.Top)*ARichEdit.Font.PixelsPerInch/ACanvas.Font.PixelsPerInch);
        ARichEdit.Lines:=Text;
        result:=PrintRTFToCanvas(ACanvas,FromChar,ToChar,ARichEdit,ARect,RenderIt);
        ARichEdit.Free;
      end;
    end;
     
    procedure TFMemo.BprintClick(Sender: TObject);
    var RectGauche, RectDroite,CurrentRect:TRect;
        i,x,y:integer;
        FaireGauche:boolean;
        FromChar, ToChar : integer;
        marge:integer;
    begin
      printer.Orientation:=poLandscape;
      marge:=round(printer.PageWidth/50);
      RectGauche:=Rect(marge,marge,(printer.PageWidth div 2)-marge,(printer.PageHeight)-marge);
      RectDroite:=Rect((printer.PageWidth div 2)+marge,marge,printer.PageWidth-marge,printer.PageHeight-marge);
     
      FaireGauche:=true;
      printer.BeginDoc;
      printer.Canvas.Brush.Style:=bsClear;
      Printer.Canvas.Brush.Color := clBlack;
     
      i:=0;
      FromChar:=0;
      while FromChar<Length(memo1.Lines.Text) do
      begin
        if FaireGauche then CurrentRect:=RectGauche else CurrentRect:=RectDroite;
        Tochar:=-1;
        ToChar:=PrintTextToCanvas(printer.Canvas,FromChar,ToChar,memo1.Lines,CurrentRect,True);
        Printer.Canvas.FrameRect(CurrentRect);
        FromChar:=ToChar;
        if odd(i) then printer.NewPage;
        FaireGauche:=not FaireGauche;
        inc(i);
      end;
      printer.EndDoc;
     
    end;
     
    end.
    Si ta réponse est résolue, n'oublies pas de marquer "Résolu".

    @+,

    Cincap

  7. #7
    Modérateur

    Homme Profil pro
    Ingénieur retraité
    Inscrit en
    Octobre 2005
    Messages
    2 396
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur retraité

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 396
    Points : 3 263
    Points
    3 263
    Par défaut
    Bonjour,

    Autre possibilité : On peut remplacer le Memo de la fiche par un RichEdit et utiliser sa méthode Print pour imprimer.

    A+.
    N'oubliez pas de consulter les FAQ Delphi et les cours et tutoriels Delphi

Discussions similaires

  1. [CR][VB6] Impression d'un état depuis VB
    Par sda dans le forum SDK
    Réponses: 3
    Dernier message: 06/02/2007, 17h27
  2. memo+fontdialog
    Par bohemianvirtual dans le forum Composants VCL
    Réponses: 2
    Dernier message: 18/07/2002, 14h27
  3. Impression d'image bmp
    Par Invité dans le forum Langage
    Réponses: 6
    Dernier message: 18/07/2002, 09h38
  4. Problème d'impression
    Par IngBen dans le forum C++Builder
    Réponses: 7
    Dernier message: 22/05/2002, 11h37
  5. [Kylix] Memo color
    Par Metal3d dans le forum EDI
    Réponses: 1
    Dernier message: 21/05/2002, 17h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo