protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); Graphics g = pe.Graphics; //alias g.SmoothingMode = SmoothingMode.HighQuality; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; //keeps text centered in cells better using (SolidBrush brushBack = new SolidBrush(this.BackColor)){ g.FillRectangle(brushBack, 0, 0, Width, Height); } g.FillRectangle(Brushes.White, _marginLR, 0, Width - _marginLR * 2 - 1, SelectedLength * _heightRow); //g.FillRectangle(Brushes.LightGray,_marginLR,0,_widthLeft,SelectedLength*_heightRow);//left handles //lines are drawn above each cell for (int i = 0; i < SelectedLength; i++) { if (MinPerIncr == 10) { if (i * 2 < Pattern.Length && Pattern.Substring(i * 2, 1) == "X") { g.FillRectangle(_brushProv, _marginLR, i * _heightRow, _widthLeft, _heightRow); } if (i * 2 < PatternSecondary.Length && PatternSecondary.Substring(i * 2, 1) == "X") { g.FillRectangle(_brushProv2, _marginLR + _widthLeft, i * _heightRow, _widthLeft, _heightRow); } if (i % 6 == 0) { g.DrawLine(Pens.Black, _marginLR, i * _heightRow, Width - _marginLR - 1, i * _heightRow); } else { g.DrawLine(Pens.Silver, _marginLR, i * _heightRow, Width - _marginLR - 1, i * _heightRow); } } else if (MinPerIncr == 15) { if (i * 3 < Pattern.Length && Pattern.Substring(i * 3, 1) == "X") { g.FillRectangle(_brushProv, _marginLR, i * _heightRow, _widthLeft, _heightRow); } if (i * 3 < PatternSecondary.Length && PatternSecondary.Substring(i * 3, 1) == "X") { g.FillRectangle(_brushProv2, _marginLR + _widthLeft, i * _heightRow, _widthLeft, _heightRow); } if (i % 4 == 0) { g.DrawLine(Pens.Black, _marginLR, i * _heightRow, Width - _marginLR - 1, i * _heightRow); } else { g.DrawLine(Pens.Silver, _marginLR, i * _heightRow, Width - _marginLR - 1, i * _heightRow); } } else //5 { if (i * 1 < Pattern.Length && Pattern.Substring(i * 1, 1) == "X") { g.FillRectangle(_brushProv, _marginLR, i * _heightRow, _widthLeft, _heightRow); } if (i * 1 < PatternSecondary.Length && PatternSecondary.Substring(i * 1, 1) == "X") { g.FillRectangle(_brushProv2, _marginLR + _widthLeft, i * _heightRow, _widthLeft, _heightRow); } if (i % 12 == 0) { g.DrawLine(Pens.Black, _marginLR, i * _heightRow, Width - _marginLR - 1, i * _heightRow); } else { g.DrawLine(Pens.Silver, _marginLR, i * _heightRow, Width - _marginLR - 1, i * _heightRow); } } } //ProvBarText------------------------------------------------------------------------------- //needs to be a second loop due to descending characters like g that need to draw on top of gridlines for (int i = 0; i < SelectedLength; i++) { if (_provBarText.Length > i && _provBarText[i] != ' ') { //float widthChar=g.MeasureString(ProvBarText.Substring(i,1),Font).Width; //float xCenter=_marginLR+_widthLeft+(Width-_marginLR*2f-_widthLeft)/2f; //g.DrawString(ProvBarText.Substring(i,1),_fontCourier,Brushes.Black,xCenter-widthChar/2f,i*_heightRow+1); g.DrawString(_provBarText.Substring(i, 1), _fontCourier, Brushes.Black, _marginLR + (_widthLeft * 2) + 1, i * _heightRow + 1); } } //outline----------------------------------------------------------------------------------- g.DrawLine(Pens.Silver, _marginLR + _widthLeft, 0, _marginLR + _widthLeft, SelectedLength * _heightRow); //first vertical line closer to L g.DrawLine(Pens.Silver, _marginLR + (_widthLeft * 2), 0, _marginLR + (_widthLeft * 2), SelectedLength * _heightRow); //second vertical line closer to R g.DrawLine(Pens.Gray, _marginLR, 0, Width - _marginLR - 1, 0); //top g.DrawLine(Pens.Gray, _marginLR, 0, _marginLR, SelectedLength * _heightRow); //L above slider g.DrawLine(Pens.Gray, Width - _marginLR - 1, 0, Width - _marginLR - 1, SelectedLength * _heightRow); //R above slider if (DesignMode) { g.DrawLine(Pens.LightGray, _marginLR, Height - 1, Width - _marginLR - 1, Height - 1); //bottom g.DrawLine(Pens.LightGray, _marginLR, SelectedLength * _heightRow, _marginLR, Height); //L below slider g.DrawLine(Pens.LightGray, Width - _marginLR - 1, SelectedLength * _heightRow, Width - _marginLR - 1, Height); //R below slider } //Slider------------------------------------------------------------------------------------ _rectangleFSlider = new RectangleF(0, SelectedLength * _heightRow, Width - 1, _heightRow + 4); GraphicsPath graphicsPath = ContrApptPanel.GetRoundedPath(_rectangleFSlider, 2); if (_rectangleFSlider.Contains(_pointMouse) || _isDraggingSlider) { g.FillPath(Brushes.White, graphicsPath); //hover effect } else { using (SolidBrush brush237 = new SolidBrush(Color.FromArgb(237, 237, 237))){ g.FillPath(brush237, graphicsPath); } } using (Pen pen = new Pen(_colorSliderOutline)){ g.DrawPath(pen, graphicsPath); } TimeSpan timeSpan = TimeSpan.FromMinutes(Pattern.Length * 5); string strTime = timeSpan.ToString("h':'mm"); g.DrawString(strTime, Font, Brushes.Black, 9, SelectedLength * _heightRow + 3); //SelectedIndex------------------------------------------------------------------------------ if (SelectedIndex > -1 && _isCursorFlashOn && this.Focused) { g.DrawLine(Pens.Red, _marginLR + (_widthLeft * 2) + 3, SelectedIndex * _heightRow + 2, _marginLR + (_widthLeft * 2) + 3, SelectedIndex * _heightRow + 11); } }
private void ToggleProv2(int index) { if (ColorProv2 == Color.White) { return; //No secondary provider has been selected } if (MinPerIncr == 10) { int pos = index * 2; if (pos > PatternSecondary.Length - 1) { pos = PatternSecondary.Length - 1; //should never hit this failsafe } string strReplace = PatternSecondary.Substring(pos, 1) == "X"?"/":"X"; //Opposite, either X or / string patternNew = ""; if (pos > 0) { patternNew = PatternSecondary.Substring(0, pos); } patternNew += strReplace; patternNew += strReplace; if (pos + 2 < PatternSecondary.Length) { patternNew += PatternSecondary.Substring(pos + 2); } PatternSecondary = patternNew; } else if (MinPerIncr == 15) { int pos = index * 3; if (pos > PatternSecondary.Length - 1) { pos = PatternSecondary.Length - 1; } string strReplace = PatternSecondary.Substring(pos, 1) == "X"?"/":"X"; string patternNew = ""; if (pos > 0) { patternNew = PatternSecondary.Substring(0, pos); } patternNew += strReplace; patternNew += strReplace; patternNew += strReplace; if (pos + 3 < PatternSecondary.Length) { patternNew += PatternSecondary.Substring(pos + 3); } PatternSecondary = patternNew; } else //5 { int pos = index * 1; if (pos > PatternSecondary.Length - 1) { pos = PatternSecondary.Length - 1; } string strReplace = PatternSecondary.Substring(pos, 1) == "X"?"/":"X"; string patternNew = ""; if (pos > 0) { patternNew = PatternSecondary.Substring(0, pos); } patternNew += strReplace; if (pos + 1 < PatternSecondary.Length) { patternNew += PatternSecondary.Substring(pos + 1); } PatternSecondary = patternNew; } }