当我关闭打印预览窗口或移动打印预览窗口时,我在以下代码中出现错误.我似乎无法理解为什么会这样.它发生在g.DrawString()行上.据我所知,没有任何事情被处理掉.
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); 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,Single x,Single y) at ScanPro.CustomControls.UserLabel.OnPaint(PaintEventArgs e)
任何帮助,将不胜感激.
谢谢.