當我關閉打印預覽窗口或移動打印預覽窗口時,我在下面的代碼中收到錯誤。我似乎無法理解爲什麼會發生這種情況。它發生在g.DrawString()行上。據我所知,也沒有處理任何東西。錯誤的C#參數無效錯誤
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush textBrush = new SolidBrush(this.ForeColor);
float width = TextRenderer.MeasureText(Text, this.Font).Width;
float height = TextRenderer.MeasureText(Text, this.Font).Height;
float radius = 0f;
if (ClientRectangle.Width < ClientRectangle.Height)
radius = ClientRectangle.Width * 0.9f/2;
else
radius = ClientRectangle.Height * 0.9f/2;
switch (orientation)
{
case Orientation.Rotate:
{
double angle = (_rotationAngle/180) * Math.PI;
g.TranslateTransform(
(ClientRectangle.Width + (float)(height * Math.Sin(angle)) - (float)(width * Math.Cos(angle)))/2,
(ClientRectangle.Height - (float)(height * Math.Cos(angle)) - (float)(width * Math.Sin(angle)))/2);
g.RotateTransform((float)_rotationAngle);
g.DrawString(Text, this.Font, textBrush, 0, 0);
g.ResetTransform();
}
break;
}
}
第一部分:
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, Single x, Single y)
at ScanPro.CustomControls.UserLabel.OnPaint(PaintEventArgs e)
任何幫助,將不勝感激。
謝謝。
什麼是例外? – jason 2009-11-10 14:57:38
System.ArgumentException {「參數無效。」} – Nathan 2009-11-10 15:00:43
「文本」中的內容是什麼? – 2009-11-10 16:41:45