void drawStep(Panel panel1) {
int[] rowHeights = new int[] { 100, 200, 80, 40 }; ///直径 int rectLenth = 20;
Graphics graphics = panel1.CreateGraphics();
graphics.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿 graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality;
int lenTotal = 0;
//绘制中线 graphics.Clear(Color.LightYellow); Color c = new Color(); c = Color.Black; for (int i = 0; i < rowHeights.Length; i++) { int rowHeight = rowHeights[i]; lenTotal += rowHeight;
int x1 = panel1.Width / 2; int y1 = 0; int x2 = x1; int y2 = rowHeight;
int rectX = x1 - rectLenth / 2;
int rectsemi = rectLenth / 2;
int rectY = rowHeight / 2 - rectLenth / 2;
if (i == 0) {
c = Color.Red;
} else {
y1 = lenTotal - rowHeight;
y2 = lenTotal;
c = Color.Black;
rectY = y1 + rowHeights[i] / 2 - rectsemi; }
graphics.DrawLine(new Pen(c, 5), x1, y1, x2, y2);
graphics.FillEllipse(new SolidBrush(c), new Rectangle(new Point(rectX, rectY), new Size(rectLenth, rectLenth))); } }
刚发现个现象,用Alt键时绘的图居然消息了,要放在paint事件中,就不会了