private void drawaclass(Graphics g, Classob aclass) { Pen mypen = new Pen(Color.Black, 2); Rectangle rect = getclassrect(aclass); // g.FillRectangle(Brushes.White, rect);//直角时涂白使用 StringFormat centerStringFormat = new StringFormat(); centerStringFormat.Alignment = StringAlignment.Center; centerStringFormat.LineAlignment = StringAlignment.Center; // g.FillRectangle(new SolidBrush(aclass.colorintable), rect);//这个不是圆角 g.FillSmoothClassRectangle(rect, aclass.colorintable);//这个是个扩展方法 Font font = new Font("方正卡通简体", 12, FontStyle.Bold, GraphicsUnit.Point); g.DrawString(aclass.classname + "\r\n" + aclass.room, font, Brushes.Black, rect, centerStringFormat); // g.DrawRectangle(mypen, rect);//直角时描边使用 }
private Rectangle getclassrect(Classob aclass) { int begin = aclass.timebegin; int week = aclass.weekcode + 1; int x = week * weekdaywidth; int y; int end = aclass.timeend; int length = (end - begin + 1) * classheight; if (begin <= 4) { y = weekdayheight + (begin - 1) * classheight; } else if (begin <= 8) { y = weekdayheight + dinnertimeheight + (begin - 1) * classheight; } else { y = weekdayheight + dinnertimeheight * 2 + (begin - 1) * classheight; } return(new Rectangle(x, y, classwidth, length)); }