如果我有一个面板,我在其 CreateGraphics() 对象上绘制通用形状,如下所示:
public static void DrawRoundRectWithText(Graphics g, Pen p, float x, float y, float width, float height, float radius, string textFirstLike, string textSecondsLine, bool hasGate, Color color)
{
System.Drawing.Graphics formGraphics = g;
g.InterpolationMode = InterpolationMode.High;
g.SmoothingMode = SmoothingMode.HighQuality;
drawBrush.Color = color;
Rectangle rect = new Rectangle((int)x, (int)y, (int)width, (int)height);
p.Width = RECTANGLE_BORDER;
formGraphics.FillRectangle(drawBrush, rect);
p.Color = RECTANGLE_COLOR;
formGraphics.DrawRectangle(p, rect);
DrawString(g, textFirstLike, x + TEXT_OFFSET_X, y + height / 4, PRIMARY_TEXT_FONT_SIZE, (int)width);
DrawString(g, textSecondsLine, x + TEXT_OFFSET_X, y + height / 2, SECONDARY_TEXT_FONT_SIZE, (int)width);
int gateWidth = QuestNode.GATE_RADIUS;
int gateHeight = QuestNode.GATE_RADIUS;
if (hasGate)
{
drawBrush.Color = GATE_COLOR;
Rectangle circle = new Rectangle((int)(x + width) - gateWidth/2, (int)(y + height) - gateHeight/2, gateWidth, gateHeight);
formGraphics.FillEllipse(drawBrush, circle);
formGraphics.DrawEllipse(p, circle);
}
Point[] diamondPoints = new Point[4];
diamondPoints[0] = new Point((int)(x - gateWidth / 2), (int)y);
diamondPoints[1] = new Point((int)x, (int)(y - gateHeight / 2));
diamondPoints[2] = new Point((int)(x + gateWidth / 2), (int)y);
diamondPoints[3] = new Point((int)x, (int)(y + gateHeight / 2));
drawBrush.Color = Color.LightGray;
formGraphics.FillPolygon(drawBrush, diamondPoints);
formGraphics.DrawPolygon(p, diamondPoints);
}
有没有办法可以放大/缩小面板,从而自动缩小形状?