protected override void OnPaint(System.Drawing.Graphics g) { double maxheight = DoPaint(g, false, 0); cc.Size = new Size(Width, (int)Math.Ceiling(Height - maxheight)); cc.Paint(g); DoPaint(g, true, Height - maxheight); }
/// <summary> /// Paint me /// </summary> /// <param name="g"></param> protected override void OnPaint(System.Drawing.Graphics g) { //Y coordinate for ChControl int y = 5; //X coordiante for ChControl int x = 5; //Height of ChControl int height = Height; //Width of ChControl int width = Width; //Draw title if (ShowTitle) { SizeF ts = g.MeasureString(Title, bold, Width, tsf); g.DrawString(Title, bold, new SolidBrush(ForeColor), new RectangleF(new Point(0, y), new SizeF(Width, ts.Height)), tsf); //Add Title Height to y coordinate y += (int)Math.Ceiling(ts.Height); } //Draw XLabel SizeF xs = g.MeasureString(XLabel, Font, Width, tsf); g.DrawString(XLabel, Font, new SolidBrush(ForeColor), new RectangleF(new Point(0, Height - (int)Math.Ceiling(xs.Height)), new SizeF(Width, xs.Height)), tsf); //Subtract X Label height from ChControl height height -= (int)Math.Ceiling(xs.Height); //Draw Y Titles if (ShowLegend) { // //Draw Legend if (legendhorizontal) { ly.Font = Font; ly.MeasureContent(g); GraphicsContainer gc1 = g.BeginContainer(); g.TranslateTransform(Width - ly.Width - 1, 1); ly.Paint(g); g.EndContainer(gc1); //Subtract legend width from ChControl width width -= ly.Width + 1; } else { GraphicsContainer gc1 = g.BeginContainer(); g.TranslateTransform(1, this.Height / 2 - ly.Height / 2); ly.Paint(g); g.EndContainer(gc1); x += ly.Width + 1; } // } // //Draw Single Y Title // else if (YLabels.Length == 1) // { // GraphicsContainer gc1 = g.BeginContainer(); // SizeF ys = g.MeasureString(YLabels[0],Font,Height,tsf); // g.RotateTransform(-90); // g.DrawString(YLabels[0],Font,new SolidBrush(ForeColor), // new RectangleF(new PointF(-Height,0),new SizeF(Height,ys.Height)),tsf); // g.EndContainer(gc1); // // //Add Y title height to ChControl X coordinate // x += (int)Math.Ceiling(ys.Height); // } } //Draw X axis label if (XType != null) { SizeF xss = g.MeasureString(XType, Font); g.DrawString(XType, Font, new SolidBrush(ForeColor), width - xss.Width, height - xss.Height); //Subtract Height of x axis label from ChControl height height -= (int)Math.Ceiling(xss.Height); } //Draw Y axis label if (YType != null) { SizeF xss = g.MeasureString(YType, Font); g.DrawString(YType, Font, new SolidBrush(ForeColor), 0, y); //Set the x coordinate to new value if it is too small if (x < (int)Math.Ceiling(xss.Width)) { x = (int)Math.Ceiling(xss.Width); } } //Set Location and Size of ChControl and Paint it GraphicsContainer gc = g.BeginContainer(); cc.Location = new Point(x, y); cc.Paint(g); g.EndContainer(gc); }