さて、印刷メソッドに使用する Queue があります。印刷する必要がある各行のテキストと選択したフォントを保存します。次のループは、キューの内容を出力することになっていますが、オブジェクトへの実際の参照ではなく、オブジェクトの値を返すように見えます。参照を返すようにする方法はありますか?
while (reportData.Count > 0 && checkLine(yPosition, e.MarginBounds.Bottom, reportData.Peek().selectedFont.Height))
{
ReportLine currentLine = reportData.Peek();
maxCharacters = e.MarginBounds.Width / (int)currentLine.selectedFont.Size;
if (currentLine.text.Length > maxCharacters)
{
e.Graphics.DrawString(currentLine.text.Substring(0, maxCharacters), currentLine.selectedFont, Brushes.Black, xPosition, yPosition);
yPosition += currentLine.selectedFont.Height;
currentLine.text.Remove(0, maxCharacters);
}
else
{
e.Graphics.DrawString(currentLine.text, currentLine.selectedFont, Brushes.Black, xPosition, yPosition);
yPosition += currentLine.selectedFont.Height;
reportData.Dequeue();
}
}
ReportLine は構造体であるため、特に指定がない限り、常に値渡しになります。2つの情報を保持することが唯一の目的であるため、クラスに変更したくありません。
[編集]
ReportLine は次のようになります。それは非常に簡単です:
public struct ReportLine
{
public string text;
public Font selectedFont;
}