// *********************************************************************** // HELPER: DrawBitmap // INPUT : Graphics, menu item, state of the item // NOTES : Renders the bitmap for the current item taking into account the // current state of the item public virtual void DrawBitmap(Graphics g, MenuItem item, DrawItemState itemState) { // Grab the current state of the menu item //bool isSelected = (itemState & DrawItemState.Selected) != 0; bool isDisabled = (itemState & DrawItemState.Disabled) != 0; bool isChecked = (itemState & DrawItemState.Checked) != 0; Bitmap bmp = null; // Determine the bitmap to use if checked, radio-checked, normal if (isChecked == true) { if (item.RadioCheck) { bmp = (Bitmap)GetEmbeddedImage(this.RadioCheckIcon); } else { bmp = (Bitmap)GetEmbeddedImage(this.CheckIcon); } } else { if (item.RadioCheck) { bmp = (Bitmap)GetEmbeddedImage(this.RadioUnCheckIcon); } else { if (menuItemIconCollection.ContainsKey(item)) { bmp = (Bitmap)GetEmbeddedImage(menuItemIconCollection[item]); } } } // if no valid bitmap is found, exit. if (bmp == null) { return; } // Make the bitmap transparent bmp.MakeTransparent(); // Render the bitmap (the bitmap is grayed out if the // item is disabled) if (isDisabled == true) { ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(0.2F); Rectangle tmpRect = new Rectangle((int)BitmapBounds.X + 2, (int)BitmapBounds.Y + 2, (int)BitmapBounds.Width - 2, (int)BitmapBounds.Right - 2); g.DrawImage(bmp, tmpRect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, imageAttr); imageAttr.ClearGamma(); } else { g.DrawImage(bmp, BitmapBounds.X + 2, BitmapBounds.Y + 2); } // Free the resource. bmp.Dispose(); }