【发布时间】:2015-11-19 04:10:05
【问题描述】:
我有一个包含面板的表单,在此面板中我绘制形状,如矩形和圆形,我需要放大这些形状,我看到了几个选项,但其中大多数使用 PictureBox。我应该使用位图将面板区域创建为位图并更改缩放系数吗?如果我想要平移并且不绘制不适合面板大小的图像,这是否会进一步帮助我。
这是我的代码的快照
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = panel1.CreateGraphics();
SolidBrush myBrush = new SolidBrush(Color.Black);
Pen p = new Pen(Color.Black);
int RecScale = 1;
foreach (CircuitData.ResistorRow resistorRow in ResistorData.Resistor)
{
RectangleF rec = new RectangleF((float)(resistorRow.CenterX - resistorRow.Length / 2), (float)(resistorRow.CenterY - resistorRow.Width/ 2), (float)resistorRow.Length, (float)resistorRow.Width);
float orientation = 360 - (float)resistorRow.Orientation;
PointF center = new PointF((float)resistorRow.CenterX, (float)resistorRow.CenterY);
PointF[] points = CreatePolygon(rec, center, orientation);
if (!Double.IsNaN(resistorRow.HiX) && !Double.IsNaN(resistorRow.HiY))
{
g.FillEllipse(myBrush, (float)resistorRow.HiX - 5 , (float)resistorRow.HiY - 5, 10, 10);
g.DrawLine(p, new PointF((float)resistorRow.HiX, (float)resistorRow.HiY), center);
}
g.FillPolygon(myBrush, points);
}
}
能否提供示例代码。 非常感谢
日本
【问题讨论】:
-
如果您愿意,您可以缩放 Graphics 对象。但首先修复您的绘画事件中的损坏代码!!!将
Graphics g = panel1.CreateGraphics();换成Graphics g = e.Graphics;