Je travaille dans le projet WinForms et j'ai les requêtes dans Impression du texte. J'ai donc créé l'exemple simple pour tester le problème. Dans le formulaire, j'ai dessiné la chaîne entre deux lignes manuellement en utilisant Form.Graphics et fait la même chose en utilisant PrintPageEventArgs.Graphics dans l'événement PrintDocument.PrintPage. La position de dessin est modifiée dans l'aperçu avant impression. Veuillez voir l'image ci-dessous, qui montre le problème (c'est-à-dire que le dessin des lignes est différent entre Form.Graphics et PrintPageEventArgs.Graphics). S'il vous plaît laissez-moi savoir, pourquoi la position de dessin est changé?La position du dessin est modifiée dans PrintPageEventArgs.Graphis
public Form1()
{
InitializeComponent();
this.Paint += Form1_Paint;
}
void Document_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red)), 10, 10, 10, 25);
e.Graphics.DrawString("Some Chars are getting Cut in Print Preview", this.Font, new SolidBrush(Color.Red), 10, 10);
e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red)), 228, 10, 228, 25);
}
void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red)), 10, 10, 10, 25);
e.Graphics.DrawString("Some Chars are getting Cut in Print Preview", this.Font, new SolidBrush(Color.Red), 10, 10);
e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red)), 228, 10, 228, 25);
}
private void button1_Click(object sender, EventArgs e)
{
PrintPreviewDialog ppd = new PrintPreviewDialog();
PrintDocument doc = new PrintDocument();
ppd.Document = doc;
ppd.Document.PrintPage += Document_PrintPage;
ppd.ShowDialog();
}
Exemple: TestSample
Merci à l'avance.
Est-ce que ma réponse a aidé? – TheLethalCoder
Bonjour, je ne peux pas utiliser Graphics.MeasureStrings() dans mon niveau de production. car chaque texte d'une colonne aura une longueur différente. – Prithiv
Puis mesurez toutes les cordes et prenez le maximum ... – TheLethalCoder