私はWinFormsプロジェクトで作業していますが、テキストの印刷でクエリを取得しています。だから私は問題をテストするための簡単なサンプルを作成しました。 Formでは、Form.Graphicsを使用して手動で2つの行の間に文字列を描画し、PrintDocument.PrintPageイベントでPrintPageEventArgs.Graphicsを使用して同じ行を再度実行しました。印刷プレビューで描画位置が変更されます。下の図を参照して問題を示してください(つまり、線を描くことはForm.GraphicsとPrintPageEventArgs.Graphicsで異なります)。私に教えてください、なぜ描画位置が変更されますか?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();
}
サンプル:事前にTestSample
感謝。
私の回答は役に立ちましたか? – TheLethalCoder
こんにちは、プロダクションレベルでGraphics.MeasureStrings()を使用することはできません。列の各テキストの長さが異なるためです。 – Prithiv
次に、すべての文字列を測定し、最大値を取る。 – TheLethalCoder