Auteur de questions
Imprimer donnée dataGridView

Question
-
Bonjour,
toujours dans ce logiciel de recette là, me voici au bouton imprimer.
L'idée est que le client possède un dataGridView de toutes ses recettes. L'objectif présent de l'impression:
Il sélectionne la recette à imprimer, clique sur imprimer et une feuille sort sous cette forme:
TITRE ENTREPRISE DU CLIENT
Recette: TITRE (exemple: Thé pêche)
Composant - Catégorie - Prix
pêche thé 5
fleur décoration 6.60
Massepin Arome 4
________________________________
Prix Total: 15.6
------------------------------------------------
Toutes les réponses
-
-
Hello,
J'ai cherché un peu sur google et le seul tuto que j'ai à peu près trouvé est le suivant:
http://neo.developpez.com/tutos/cr/csharp/
Mais je n'ai pas l'impression qu'il m'ai eclaircis la chandelle, j'aurais besoin de plus d'explication.
A+
-
Tiens sinon j'ai trouvé quelque chose d'assez simple ici:
http://www.c-sharpcorner.com/UploadFile/mgold/PrintingW2Form09162005061136AM/PrintingW2Form.aspx
C'est basé sur des forms uniquement donc du basique mais vu ce que tu cherches à faire pas besoin de quelquechose de compliqué. Avec un peu d'adaptation tu y arriveras très bien!
Ensuite il te suffira d'ajouter dynamiquement des labels (contenant tes valeurs) pour faire ta mise en page et hop le tour est joué!
Sinon crystal report c'est un peu la même logique que les rapports access et si tu cherches bien tu trouveras un peu plus d'infos de ce côté là (Enfin le tutoriel à l'air clair après une lecture rapide).
-
-
Je pense que tu parles du gif qu'il à mis en background de son form. Il fait ça pour utiliser le scan d'un formulaire papier et pourvoir placer ses labels et autres.
Tiens voila une version qui n'utilise pas ça:
Code Snippetprivate void DrawAll(Graphics g)
{
// Create the source rectangle from the BackgroundImage Bitmap Dimensions
RectangleF srcRect = new Rectangle(0, 0, this.Width, Height); //RectangleF srcRect = new Rectangle(0, 0, this.BackgroundImage.Width, BackgroundImage.Height); // Create the destination rectangle from the printer settings holding printer page dimensions int nWidth = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Width; int nHeight = printDocument1.PrinterSettings.DefaultPageSettings.PaperSize.Height; RectangleF destRect = new Rectangle(0, 0, nWidth, nHeight / 2); // Draw the image scaled to fit on a printed page //g.DrawImage(this.BackgroundImage, destRect, srcRect, GraphicsUnit.Pixel); // Determine the scaling factors of each dimension based on the bitmap and the printed page dimensions // These factors will be used to scale the positioning of the contro contents on the printed form float scalex = destRect.Width / srcRect.Width; float scaley = destRect.Height / srcRect.Height; Pen aPen = new Pen(Brushes.Black, 1); // Cycle through each control. Determine if it's a checkbox or a textbox and draw the information inside // in the correct position on the form for (int i = 0; i < this.Controls.Count; i++){
// Check if its a TextBox type by comparing to the type of one of the textboxes if (Controls[i].GetType() == this.textBox1.GetType()){
// Unbox the Textbox TextBox theText = (TextBox)Controls[i]; // Draw the textbox string at the position of the textbox on the form, scaled to the print pageg.DrawString(theText.Text, theText.Font,
Brushes.Black, theText.Bounds.Left * scalex, theText.Bounds.Top * scaley, new StringFormat());}
if (Controls[i].GetType() == this.checkBox1.GetType()){
// Unbox the Checkbox CheckBox theCheck = (CheckBox)Controls[i]; // Draw the checkbox rectangle on the form scaled to the print page Rectangle aRect = theCheck.Bounds; //g.DrawRectangle(aPen, aRect.Left * scalex, aRect.Top * scaley, aRect.Width * scalex, aRect.Height * scaley); // If the checkbox is checked, Draw the x inside the checkbox on the form scaled to the print page if (theCheck.Checked){
g.DrawString(
"x", theCheck.Font, Brushes.Black, theCheck.Left * scalex + 1, theCheck.Top * scaley + 1, new StringFormat());}
}
}
}
Par contre il te faut au moins une checkbox et une texbox (appelés respectivement texbox1 et checkbox1) pour que cet exemple marche. Après tu peux modifier cette partie en fonction de tes besoins.
-
-
Le printer étant considéré comme un "écran" dans lequel tu dois dessiner, tu trouveras difficilement plus simple que de faire des drawstring.
Maintenant si tu veux un truc qui te fasse de la mise en page et tout et tout en 3 clics de souris, je ne vois pas d'autres solutions que crystal report! les concepts sont un peu difficiles à assimiler mais ton cas est très simple et donc ça devrait aller vite.