public KryptonKnobControlEnhanced() { _dottedPen = new Pen(KryptonKnobUtilities.GetDarkColour(BackColor, 40)) { DashStyle = DashStyle.Dash, DashCap = DashCap.Flat }; InitializeComponent(); _knobTypeface = new Font(Font.FontFamily, Font.Size); _scaleTypeface = new Font(Font.FontFamily, Font.Size); // Properties initialisation // "start angle" and "end angle" possible values: // 90 = bottom (minimum value for "start angle") // 180 = left // 270 = top // 360 = right // 450 = bottom again (maximum value for "end angle") // So the couple (90, 450) will give an entire circle and the couple (180, 360) will give half a circle. _startAngle = 135; _endAngle = 405; _deltaAngle = _endAngle - _startAngle; _minimum = 0; _maximum = 100; _scaleDivisions = 11; _scaleSubDivisions = 4; _mouseWheelBarPartitions = 10; _scaleColour = Color.Black; _knobBackColour = Color.White; SetDimensions(); if (((_palette != null))) { _palette.PalettePaint += OnPalettePaint; } KryptonManager.GlobalPaletteChanged += OnGlobalPaletteChanged; _palette = KryptonManager.CurrentGlobalPalette; _paletteRedirect = new PaletteRedirect(_palette); _paletteBack = new PaletteBackInheritRedirect(_paletteRedirect); _paletteBorder = new PaletteBorderInheritRedirect(_paletteRedirect); _paletteContent = new PaletteContentInheritRedirect(_paletteRedirect); InitiliseColourScheme(); }
/// <summary> /// Set position of button inside its rectangle to insure that divisions will fit. /// </summary> private void SetDimensions() { Font font; // Rectangle float x, y, w, h; x = 0; y = 0; w = h = Width; // Calculate ratio _drawRatio = w / 150; if (_drawRatio == 0.0) { _drawRatio = 1; } if (_showLargeScale) { Graphics Gr = this.CreateGraphics(); string strvalmax = _maximum.ToString(); string strvalmin = _minimum.ToString(); string strval = strvalmax.Length > strvalmin.Length ? strvalmax : strvalmin; double val = Convert.ToDouble(strval); //double val = _maximum; String str = String.Format("{0,0:D}", (int)val); float fSize = _scaleTypeface.Size; if (_scaleTypefaceAutoSize) { fSize = (float)(6F * _drawRatio); if (fSize < 6) { fSize = 6; } font = new Font(_scaleTypeface.FontFamily, fSize); } else { fSize = _scaleTypeface.Size; font = new Font(_scaleTypeface.FontFamily, _scaleTypeface.Size); } SizeF strsize = Gr.MeasureString(str, font); // Graduations outside _gradLength = 4 * _drawRatio; if (_drawDivInside) { // Graduations inside : remove only 2*8 pixels //x = y = 8; x = y = _gradLength; w = Width - 2 * x; } else { // remove 2 * size of text and length of graduation //_gradLength = 4 * _drawRatio; int strw = (int)strsize.Width; int strh = (int)strsize.Height; int max = Math.Max(strw, strh); x = max; y = max; w = (int)(Width - 2 * max - _gradLength); } if (w <= 0) { w = 1; } h = w; // Rectangle of the rounded knob this._rKnob = new Rectangle((int)x, (int)y, (int)w, (int)h); Gr.Dispose(); } else { this._rKnob = new Rectangle(0, 0, Width, Height); } // Center of knob this._pKnob = new Point(_rKnob.X + _rKnob.Width / 2, _rKnob.Y + _rKnob.Height / 2); // create offscreen image this._offScreenImage = new Bitmap(this.Width, this.Height); // create offscreen graphics this._gOffScreen = Graphics.FromImage(_offScreenImage); // Depends on retangle dimensions // create LinearGradientBrush for creating knob _brushKnob = new LinearGradientBrush( _rKnob, KryptonKnobUtilities.GetLightColour(_knobBackColour, 55), KryptonKnobUtilities.GetDarkColour(_knobBackColour, 55), LinearGradientMode.ForwardDiagonal); // create LinearGradientBrush for knobPointer _brushKnobPointer = new LinearGradientBrush( _rKnob, KryptonKnobUtilities.GetLightColour(_pointerColour, 55), KryptonKnobUtilities.GetDarkColour(_pointerColour, 55), LinearGradientMode.ForwardDiagonal); }