/// <summary> /// render the key onto a graphics object surface /// </summary> /// <param name="g">graphics instance to use, usually from Paint callback</param> /// <param name="keyWidth">key is drawn with this width</param> /// <param name="keyDrawArea">defines the main key area on the owning form</param> public void Paint( Graphics g, GradientKeyVisualStyle style, Int32 keyWidth, Rectangle keyDrawArea, bool selected) { Int32 xLoc = keyDrawArea.Left + (Int32)((Double)keyDrawArea.Width * mPosition); Int32 keyBtnWidth = keyWidth >> 1; ButtonState buttonStyle = ButtonState.Normal; Border3DStyle borderStyle = Border3DStyle.Sunken; // sort out visual style for the key switch (style) { case GradientKeyVisualStyle.Flat: { buttonStyle = ButtonState.Flat; borderStyle = selected?Border3DStyle.SunkenInner:Border3DStyle.Flat; } break; case GradientKeyVisualStyle.Raised: { buttonStyle = ButtonState.Normal; borderStyle = selected?Border3DStyle.Sunken:Border3DStyle.SunkenOuter; } break; case GradientKeyVisualStyle.Sunken: { buttonStyle = ButtonState.Pushed; borderStyle = selected?Border3DStyle.SunkenInner:Border3DStyle.RaisedInner; } break; } // regenerate the bounding box if it has been nullified or // if the parent volume has changed if (mBounds.IsEmpty || (keyDrawArea.GetHashCode() != mBoundHash)) { mBounds = new Rectangle( xLoc - keyBtnWidth, keyDrawArea.Top - GradientKeyLipHeight, keyWidth, keyDrawArea.Height + GradientKeyLipHeight); // save hash code of parent volume for future comparisons mBoundHash = keyDrawArea.GetHashCode(); } // render a button to act as the key container graphic ControlPaint.DrawButton( g, mBounds.Left, mBounds.Top, mBounds.Width, mBounds.Height, buttonStyle); // create new color brush if not already generated if (mDrawColorBrush == null) mDrawColorBrush = new SolidBrush(mColor); // draw a color block to show the color set on this key Rectangle colorBlock = new Rectangle( mBounds.Left + GradientKeyInteriorRim, mBounds.Top + GradientKeyLipHeight, mBounds.Width - (GradientKeyInteriorRim << 1), mBounds.Height - GradientKeyLipHeight - GradientKeyInteriorRim); if (style == GradientKeyVisualStyle.Flat) { colorBlock.Inflate(-1, -1); } g.FillRectangle(mDrawColorBrush, colorBlock); // sink the color block to give it some depth, and sink it // fully if this key is being selected and moved about ControlPaint.DrawBorder3D( g, colorBlock, borderStyle); }
/// <summary> /// render the key onto a graphics object surface /// </summary> /// <param name="g">graphics instance to use, usually from Paint callback</param> /// <param name="keyWidth">key is drawn with this width</param> /// <param name="keyDrawArea">defines the main key area on the owning form</param> public void Paint( Graphics g, GradientKeyVisualStyle style, Int32 keyWidth, Rectangle keyDrawArea, bool selected) { Int32 xLoc = keyDrawArea.Left + (Int32)((Double)keyDrawArea.Width * mPosition); Int32 keyBtnWidth = keyWidth >> 1; ButtonState buttonStyle = ButtonState.Normal; Border3DStyle borderStyle = Border3DStyle.Sunken; // sort out visual style for the key switch (style) { case GradientKeyVisualStyle.Flat: { buttonStyle = ButtonState.Flat; borderStyle = selected?Border3DStyle.SunkenInner:Border3DStyle.Flat; } break; case GradientKeyVisualStyle.Raised: { buttonStyle = ButtonState.Normal; borderStyle = selected?Border3DStyle.Sunken:Border3DStyle.SunkenOuter; } break; case GradientKeyVisualStyle.Sunken: { buttonStyle = ButtonState.Pushed; borderStyle = selected?Border3DStyle.SunkenInner:Border3DStyle.RaisedInner; } break; } // regenerate the bounding box if it has been nullified or // if the parent volume has changed if (mBounds.IsEmpty || (keyDrawArea.GetHashCode() != mBoundHash)) { mBounds = new Rectangle( xLoc - keyBtnWidth, keyDrawArea.Top - GradientKeyLipHeight, keyWidth, keyDrawArea.Height + GradientKeyLipHeight); // save hash code of parent volume for future comparisons mBoundHash = keyDrawArea.GetHashCode(); } // render a button to act as the key container graphic ControlPaint.DrawButton( g, mBounds.Left, mBounds.Top, mBounds.Width, mBounds.Height, buttonStyle); // create new color brush if not already generated if (mDrawColorBrush == null) { mDrawColorBrush = new SolidBrush(mColor); } // draw a color block to show the color set on this key Rectangle colorBlock = new Rectangle( mBounds.Left + GradientKeyInteriorRim, mBounds.Top + GradientKeyLipHeight, mBounds.Width - (GradientKeyInteriorRim << 1), mBounds.Height - GradientKeyLipHeight - GradientKeyInteriorRim); if (style == GradientKeyVisualStyle.Flat) { colorBlock.Inflate(-1, -1); } g.FillRectangle(mDrawColorBrush, colorBlock); // sink the color block to give it some depth, and sink it // fully if this key is being selected and moved about ControlPaint.DrawBorder3D( g, colorBlock, borderStyle); }