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 |