protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); try { if (fDistribution == null) { fDistribution = DiceStatistics.Odds(fDice, fConstant); } if ((fDistribution == null) || (fDistribution.Keys.Count == 0)) { return; } int delta_x = Width / 10; int delta_y = Height / 10; Rectangle rect = new Rectangle(delta_x, (3 * delta_y), Width - (2 * delta_x), Height - (5 * delta_y)); if ((fTitle != null) && (fTitle != "")) { // Draw graph title Rectangle title_rect = new Rectangle(rect.X, rect.Y - (2 * delta_y), rect.Width, delta_y); e.Graphics.FillRectangle(Brushes.White, title_rect); e.Graphics.DrawRectangle(Pens.DarkGray, title_rect); e.Graphics.DrawString(fTitle, new Font(Font.FontFamily, delta_y / 3), Brushes.Black, title_rect, fCentred); } int min_x = int.MaxValue; int max_x = int.MinValue; int max_y = int.MinValue; int sum = 0; foreach (int roll in fDistribution.Keys) { min_x = Math.Min(min_x, roll); max_x = Math.Max(max_x, roll); max_y = Math.Max(max_y, fDistribution[roll]); sum += fDistribution[roll]; } float lower_delta = (1 - fRange) / 2; float upper_delta = 1 - lower_delta; Point mouse = PointToClient(Cursor.Position); int range = max_x - min_x + 1; float width = (float)rect.Width / range; float size = Math.Min(Font.Size, width / 2); Font label_font = new Font(Font.FontFamily, size); List <PointF> levels = new List <PointF>(); int integral = 0; foreach (int roll in fDistribution.Keys) { int index = roll - min_x; float x = width * index; float height = rect.Height * (max_y - fDistribution[roll]) / max_y; RectangleF roll_rect = new RectangleF(x + rect.X, rect.Y + height, width, rect.Height - height); integral += fDistribution[roll]; float fraction = (float)integral / sum; bool highlighted = roll_rect.Contains(mouse); bool inter_quartile = ((fraction >= lower_delta) && (fraction <= upper_delta)); inter_quartile = false; float midpoint = x + rect.X + (width / 2); float y = rect.Y + height; levels.Add(new PointF(midpoint, y)); Pen pen = Pens.Gray; if (inter_quartile || highlighted) { pen = Pens.Black; } e.Graphics.DrawLine(pen, midpoint, rect.Bottom, midpoint, y); RectangleF label_rect = new RectangleF(roll_rect.Left, roll_rect.Bottom, width, delta_y); e.Graphics.DrawString(roll.ToString(), label_font, highlighted ? Brushes.Black : Brushes.DarkGray, label_rect, fCentred); } // Draw x-axis e.Graphics.DrawLine(Pens.Black, rect.Left, rect.Bottom, rect.Right, rect.Bottom); // Draw curve for (int n = 1; n < levels.Count; ++n) { e.Graphics.DrawLine(new Pen(Color.Red, 2F), levels[n - 1], levels[n]); } } catch { } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); try { if (this.fDistribution == null) { this.fDistribution = DiceStatistics.Odds(this.fDice, this.fConstant); } if (this.fDistribution != null && this.fDistribution.Keys.Count != 0) { int width = base.Width / 10; int height = base.Height / 10; Rectangle rectangle = new Rectangle(width, 3 * height, base.Width - 2 * width, base.Height - 5 * height); if (this.fTitle != null && this.fTitle != "") { Rectangle rectangle1 = new Rectangle(rectangle.X, rectangle.Y - 2 * height, rectangle.Width, height); e.Graphics.FillRectangle(Brushes.White, rectangle1); e.Graphics.DrawRectangle(Pens.DarkGray, rectangle1); e.Graphics.DrawString(this.fTitle, new System.Drawing.Font(this.Font.FontFamily, (float)(height / 3)), Brushes.Black, rectangle1, this.fCentred); } int num = 2147483647; int num1 = -2147483648; int num2 = -2147483648; int item = 0; foreach (int key in this.fDistribution.Keys) { num = Math.Min(num, key); num1 = Math.Max(num1, key); num2 = Math.Max(num2, this.fDistribution[key]); item += this.fDistribution[key]; } float single = (1f - this.fRange) / 2f; float single1 = 1f - single; Point client = base.PointToClient(System.Windows.Forms.Cursor.Position); int num3 = num1 - num + 1; float width1 = (float)rectangle.Width / (float)num3; float single2 = Math.Min(this.Font.Size, width1 / 2f); System.Drawing.Font font = new System.Drawing.Font(this.Font.FontFamily, single2); List <PointF> pointFs = new List <PointF>(); int item1 = 0; foreach (int key1 in this.fDistribution.Keys) { float single3 = width1 * (float)(key1 - num); float height1 = (float)(rectangle.Height * (num2 - this.fDistribution[key1]) / num2); RectangleF rectangleF = new RectangleF(single3 + (float)rectangle.X, (float)rectangle.Y + height1, width1, (float)rectangle.Height - height1); item1 += this.fDistribution[key1]; float single4 = (float)item1 / (float)item; bool flag = rectangleF.Contains(client); bool flag1 = (single4 < single ? false : single4 <= single1); flag1 = false; float x = single3 + (float)rectangle.X + width1 / 2f; float y = (float)rectangle.Y + height1; pointFs.Add(new PointF(x, y)); Pen gray = Pens.Gray; if (flag1 || flag) { gray = Pens.Black; } e.Graphics.DrawLine(gray, x, (float)rectangle.Bottom, x, y); RectangleF rectangleF1 = new RectangleF(rectangleF.Left, rectangleF.Bottom, width1, (float)height); e.Graphics.DrawString(key1.ToString(), font, (flag ? Brushes.Black : Brushes.DarkGray), rectangleF1, this.fCentred); } e.Graphics.DrawLine(Pens.Black, rectangle.Left, rectangle.Bottom, rectangle.Right, rectangle.Bottom); for (int i = 1; i < pointFs.Count; i++) { e.Graphics.DrawLine(new Pen(Color.Red, 2f), pointFs[i - 1], pointFs[i]); } } } catch { } }