Explication sur section de code
Bonjour tout le monde,
Je vous explique ma situation, j'ai récupérer un morceau de code d'un amis.
Je ne comprends pas dut tout ce code.
Ce code permet l'impression d'un stringgrid dans son intégralité.
Vous allez dire, demande a ton amis de t'expliquer, c'est vrai sa serait beaucoup plus simple, cependant cette amis est à l'étrangé.
Ah j'allais oublier, je travail avec borland c++ 6.
Code:
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
|
void __fastcall TForm3::SpeedButton3Click(TObject *Sender)
{// debut imprimer
TPrinter *Prntr = Printer();
Prntr->BeginDoc();
//TPrinter impression;
int nb_colon;
nb_colon = 8; // 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 = 45; // 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;
// 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
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
aleft = 200;
aright = 900;
// boucle d'increment des colonnes et pages de colonnes
for (acolonne; acolonne < no_colon; acolonne++)
{ // debut for acolonne
if(StringGrid1->Visible==true)
{
Mes_Valeurs = AnsiString(StringGrid1->Cells[acolonne][aligne]);
}else
{
Mes_Valeurs = AnsiString(StringGrid2->Cells[acolonne][aligne]);
}
TRect r = Rect(aleft, atop, aright, abottom);
Prntr->Canvas->Rectangle(r);
Prntr->Canvas->TextOutA(aleft + 20, atop + 10, Mes_Valeurs);
Prntr->Canvas->Brush->Color = clBlack;
Prntr->Canvas->FrameRect(r);
aleft = aleft + 700;
aright = aright + 700;
Prntr->Canvas->Brush->Color = clWhite;
} // fin du for acolonne
atop = atop + 100;
abottom = abottom + 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();
}
atop = 200;
abottom = 300;
} //fin for nv_pg_lign
} //fin for nv_pg_colon
Prntr->EndDoc();
Prntr->Canvas->Brush->Color = clWhite;
} // fin imprimer |
Merci d'avance de votre aide.
:lol: