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

C++Builder Discussion :

PrintDialog pour l'impression d'un StringGrid


Sujet :

C++Builder

  1. #21
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Par défaut
    Merci pour ta reponse pottiez pour mes essais j'ai utilise la fonction ci joint
    Label2->Caption = "Hauteur " + String(Printer()->PageHeight);
    et
    Label2->Caption = "Hauteur " + String(Printer()->PageWidth);
    Ce qui m'a permis de m'apercevoir que la partie graphique des rectangles etait depandant de la resolution de l'imprimante mais apparement pas le texte.
    Comme teste j'ai modifie les dimensions des rectangles sans changer le format du texte et cela a marche.
    Avec cette constation je cherche une solution pour imprimer sur toutes les imprimantes quelque soit le format.

  2. #22
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Par défaut
    J'ai trouve une solution pour imprimer le StringGrid sur plusieurs imprimantes de resolution differentes.
    C'est apparement pour les graphiques que la resolution imprimante intervient pour le texte je n'ai du faire aucune modif.
    Il faut prendre la precaution de laisser une marge basse et droite suffisante car les calculs sont arrondis (on travail sur des entiers).
    Sur les imprimantes essayees j'ai une difference en largeur et hauteur de 5mm environ ce qui reste resonnable.
    je joint le code.
    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
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
     
    { // debut imprimer
     
            TPrinter *Prntr = Printer();
                    Prntr->BeginDoc();
     
    //TPrinter impression;
    int nb_colon;
    nb_colon = 5; // NB de colonnes par page
    int acolonne;
    int nb_acolonne;
    int nb_acolonnes;
    int reste_acolonnes;
    int nv_pg_colon;
    int no_colon;
    int cpt_pg_colon;
    int dcpt_colon;
     
    int nb_lign;
    nb_lign = 60; // NB de lignes par pages
    int aligne;
    int nb_aligne;
    int nb_alignes;
    int reste_alignes;
    int nv_pg_lign;
    int no_ligne;
    int cpt_pg_lign;
    int dcpt_lign;
     
    int fin_prntr;
    fin_prntr = 0;
    int aleft;
    int atop;
    int aright;
    int abottom;
    AnsiString Mes_Valeurs;
     
    int larg_ecran;
    int ht_ecran;
    int coef_aleft;
    int coef_atop;
    int coef_aright;
    int coef_abottom;
    int coef_700;
    int coef_100;
    int coef_20;
    int coef_10;
    int coef_lar;
    int coef_ht;
     
    // calcul du nb de pages en fonction du nb de lignes et de colonnes
    nb_acolonnes = StringGrid1->ColCount;
    nb_acolonne =  nb_acolonnes / nb_colon;
    reste_acolonnes = nb_acolonnes - (nb_acolonne * nb_colon);
    if (reste_acolonnes > 0)
    {
    nv_pg_colon = nb_acolonne + 1;
    }
    else
    {
    nv_pg_colon = nb_acolonne;
    }
     
    nb_alignes = StringGrid1->RowCount;
    nb_aligne =  nb_alignes / nb_lign;
    reste_alignes = nb_alignes - (nb_aligne * nb_lign);
    if (reste_alignes > 0)
    {
    nv_pg_lign = nb_aligne + 1;
    }
    else
    {
    nv_pg_lign = nb_aligne;
    }
     
    // initialisation des variables
    //                             Y0
    aleft = 200; // X0 Gauche       |
    atop = 200; // Y0 Haut      X0--|--------|-
    //                              |        |
    //                              |        |
    aright = 900; // X1 droit      -|--------|--X1
    abottom = 300; // Y1 Bas                 |
    //                                      Y1
    // on prend la resolution de l'imprimante pour les calculs
    larg_ecran = Printer()->PageWidth;
    ht_ecran = Printer()->PageHeight;
    if (larg_ecran != 4800) // 4800 resolution de l'imprimante perso
    {
    coef_lar = (larg_ecran * 100) / 4800;
    coef_aleft = (aleft * coef_lar) / 100;
    aleft = (aleft * coef_lar) / 100;
    coef_aright = (aright * coef_lar) / 100;
    aright = (aright * coef_lar) / 100;
    coef_700 = (700 * coef_lar) / 100;
    coef_20 = (20 * coef_lar)/ 100;
    }
    else
    {
    coef_lar = 0;
    coef_aleft = aleft;
    coef_aright = aright;
    coef_700 = 700;
    coef_20 = 20;
    }
    if (ht_ecran != 6826) // 6826 resolution de l'imprimante perso
    {
    coef_ht = (ht_ecran * 100) / 6826;
    coef_atop = (atop * coef_ht) / 100;
    atop = (atop * coef_ht) / 100;
    coef_abottom = (abottom * coef_ht) / 100;
    abottom = (abottom * coef_ht) / 100;
    coef_100 = (100 * coef_ht) / 100;
    coef_10 = (10 * coef_ht) / 100;
    }
    else
    {
    coef_ht = 0;
    coef_atop = atop;
    coef_abottom = abottom;
    coef_100 = 100;
    coef_10 = 10;
    }
    //
    no_colon = 0;
     
    for (cpt_pg_colon = 1; cpt_pg_colon <= nv_pg_colon; cpt_pg_colon++)
            { //debut for nv_pg_colon
    if (nv_pg_colon == cpt_pg_colon && reste_acolonnes != 0)
            {
            no_colon = no_colon + reste_acolonnes;
            acolonne = no_colon - reste_acolonnes;
            dcpt_colon = reste_acolonnes;
            }
    else
            {
            no_colon = no_colon + nb_colon;
            acolonne = no_colon - nb_colon;
            dcpt_colon = nb_colon;
            }
     
    no_ligne = 0;
     
    // boucle de nouvelle page sens des lignes
    for (cpt_pg_lign = 1; cpt_pg_lign <= nv_pg_lign; cpt_pg_lign++)
            { //debut for nv_pg_lign
    if (nv_pg_lign == cpt_pg_lign && reste_alignes != 0)
            {
            no_ligne = no_ligne + reste_alignes;
            aligne = no_ligne - reste_alignes;
            dcpt_lign = reste_alignes;
            }
    else
            {
            no_ligne = no_ligne + nb_lign;
            aligne = no_ligne - nb_lign;
            dcpt_lign = nb_lign;
            }
     
    // boucle d'increment des lignes
    for (aligne; aligne < no_ligne; aligne++)
            { // debut for aligne
     
    coef_aleft = aleft;
    coef_aright = aright;
     
    // boucle d'increment des colonnes et pages de colonnes
    for (acolonne; acolonne < no_colon; acolonne++)
            { // debut for acolonne
     
    Mes_Valeurs = AnsiString(StringGrid1->Cells[acolonne][aligne]);
     
    TRect r = Rect(coef_aleft, coef_atop, coef_aright, coef_abottom);
     
            Prntr->Canvas->Rectangle(r);
            Prntr->Canvas->TextOutA(coef_aleft + coef_20, coef_atop + coef_10, Mes_Valeurs);
     
       Prntr->Canvas->Brush->Color = clBlack;
       Prntr->Canvas->FrameRect(r);
     
    coef_aleft = coef_aleft + coef_700;
    coef_aright = coef_aright + coef_700;
     
       Prntr->Canvas->Brush->Color = clWhite;
     
            } // fin du for acolonne
     
    coef_atop = coef_atop + coef_100;
    coef_abottom = coef_abottom + coef_100;
     
    acolonne = acolonne - dcpt_colon;
     
            } // fin du for aligne
     
    aligne = aligne - dcpt_lign;
     
    fin_prntr = fin_prntr + 1;
     
    if ( fin_prntr < (nv_pg_colon * nv_pg_lign))
    {
    Printer()->NewPage();
    }
     
    coef_atop = atop;
    coef_abottom = abottom;
     
            } //fin for nv_pg_lign
            } //fin for nv_pg_colon
     
       Prntr->EndDoc();
       Prntr->Canvas->Brush->Color = clWhite;
     
    } // fin imprimer

  3. #23
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Par défaut
    J'ai commence a regarder le composant PrintDialog et j'ai commencé a recuperer quelques renseignements.
    // Imprimante choisie = PrintDialog1->ComponentIndex; // Index de l'imprimante selectionnée
    // de_la_page = PrintDialog1->FromPage; // selection manuelle de la page xx
    // jusque_la_page = PrintDialog1->ToPage; // selection manuelle jusque la page xx
    //premiere_page = PrintDialog1->MinPage; // premiere page
    //derniere_page = PrintDialog1->MaxPage; // derniere page
    PrintDialog1->ToPage = 1; //StringGrid1->RowCount * nb_imp_colonnes;
    PrintDialog1->MaxPage = 1; //StringGrid1->RowCount * nb_imp_colonnes;
    /*
    /////////////////////
    // zone d'impression
    prAllPages le bouton radio "Tout" est selectionné.
    prSelection le bouton radio "Selection" est selectionné.
    prPageNums le bouton radio "Pages" est selectionné.
    ces trois variables s'utilisent avec "switch (PrintDialog->PrintRange)" .... "case prAllPages"

    Prntr->Orientation=poLandscape;
    poPortrait The job prints vertically on the page.
    poLandscape The job prints horizontally on the page.

    // liste des imprimantes presentes dans un ListBox
    ListBox1->Items = Printer()->Printers;

    /////////////

    poDisablePrintToFile Disables (grays) the Print To File Check box. (Applicable only if the poPrintToFile flag is set.)
    poHelp Displays a Help button in the dialog. May not work in some versions of Windows 95.
    poPageNums Enables the Pages radio button, allowing the user to specify a page range.
    poPrintToFile Displays a Print To File check box in the dialog.
    poSelection Enables the Selection radio button, allowing the user to print selected (highlighted) text.
    poWarning Generates a warning message if the user tries to send a job to an uninstalled printer.
    */
    Pour la plus part des mots de commande j'ai compris comment les utiliser mais pour les 6 derniers je n'ai rien trouve "poDisablePrintToFile" a "poWarning".
    Je n'ai pas trouve non plus comment changer le format du papier A4 .. A3 ni comment changer la qualite de l'impression et peut etre d'autres fonctions qui m'echapent

  4. #24
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Par défaut
    Je met resolu pour ce post il me manque des infos pour la gestion du composant PrintDialog je fais des recherches si besoin est je referais un post.

  5. #25
    Membre habitué
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 11
    Par défaut Impression stringgrig
    Bonjour,
    j'ai essayé le programme ça marche super bien, mais les largeurs de colonnes sont toutes égales , comment imprimer comme affiché sur l'écran c'est à dire avec des largeurs de colonnes différentes.
    merci

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. [JTable] agencer une JTable pour l'impression.
    Par lilou77 dans le forum Composants
    Réponses: 16
    Dernier message: 07/12/2005, 11h22
  2. [XML/CSS] Comment afficher le fond pour l'impression
    Par askeur dans le forum Mise en page CSS
    Réponses: 4
    Dernier message: 09/11/2005, 00h19
  3. Paramétrage pour l'impression
    Par zorba49 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 25/08/2005, 10h41
  4. Page blanche pour l'impression d'un état
    Par PAINCO dans le forum Access
    Réponses: 2
    Dernier message: 23/06/2005, 14h46

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