private void UpdateContent() { int lineHeight = Font.Height; int scaleHeight = lineHeight / 2; ClientSize = new Size(ClientSize.Width, (lineHeight * 4) + scaleHeight + (Gap * 6)); fList.Clear(); if (fRanges == null) { return; } int count = fRanges.Length; fScaleWidth = Width - (LayoutPadding * 2) - (count - 1); fRangesLength = 0.0; foreach (var range in fRanges) { VRItem item = new VRItem(); item.Range = range; item.Length = (range.Max - range.Min); item.Brush = new SolidBrush(range.Color); fList.Add(item); fRangesLength += item.Length; } int x = LayoutPadding; int y = (lineHeight + Gap) * 3; for (int i = 0; i < count; i++) { var item = fList[i]; int itemWidth = (int)(fScaleWidth * (item.Length / fRangesLength)); item.Rect = new Rectangle(x, y, itemWidth, scaleHeight); x += (itemWidth + 1); } fValuePos = LayoutPadding + (int)(fScaleWidth * (fValue / fRangesLength)); Invalidate(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Width <= 0 || Height <= 0) { return; } Graphics gfx = e.Graphics; int lineHeight = Font.Height; var titleFont = new Font(Font, FontStyle.Bold); gfx.DrawString(fTitle, titleFont, Brushes.Black, 0, 0); fScaleFont = new Font(Font.FontFamily, Font.SizeInPoints * 0.8f); int count = fList.Count; if (count > 0) { string line = string.Format(ValuesFormat, fValue); DrawText(gfx, Font, Brushes.Black, line, fValuePos, (lineHeight + Gap) * 1, -1); line = "▼"; DrawText(gfx, Font, Brushes.Black, line, fValuePos, (lineHeight + Gap) * 2, -1); int markersY = (lineHeight + Gap) * 3 + (lineHeight / 2 + Gap); for (int i = 0; i < count; i++) { VRItem item = fList[i]; DrawRect(gfx, item.Rect, item.Brush); if (i == 0) { double val = item.Range.Min; line = string.Format(ValuesFormat, val); float x = LayoutPadding + (int)(fScaleWidth * (val / fRangesLength)); DrawText(gfx, fScaleFont, Brushes.Black, line, x, markersY, 2); } else if (i == count - 1) { double val = item.Range.Min; line = string.Format(ValuesFormat, val); float x = LayoutPadding + (int)(fScaleWidth * (val / fRangesLength)); DrawText(gfx, fScaleFont, Brushes.Black, line, x, markersY, -1); val = item.Range.Max; line = string.Format(ValuesFormat, val); x = LayoutPadding + (int)(fScaleWidth * (val / fRangesLength)); DrawText(gfx, fScaleFont, Brushes.Black, line, x, markersY, 3); } else { double val = item.Range.Min; line = string.Format(ValuesFormat, val); float x = LayoutPadding + (int)(fScaleWidth * (val / fRangesLength)); DrawText(gfx, fScaleFont, Brushes.Black, line, x, markersY, -1); } } } else { //DrawRect(gfx, 10, Width - 20, fEmptyBrush); } }