/// <summary> /// This raises the <see cref="MapValueToIndicators"/> event /// </summary> /// <param name="e">The event arguments</param> protected internal virtual void OnMapValueToIndicators(MapIndicatorEventArgs e) { var handler = MapValueToIndicators; if (handler != null) { handler(this, e); } }
/// <summary> /// This raises the <see cref="MapValueToIndicators"/> event /// </summary> /// <param name="e">The event arguments</param> protected internal virtual void OnMapValueToIndicators(MapIndicatorEventArgs e) { var handler = MapValueToIndicators; if(handler != null) handler(this, e); }
/// <summary> /// This is used to draw the cell image on behalf of the cell /// </summary> /// <param name="value">The current cell value</param> /// <param name="rowIndex">The cell's row index</param> /// <returns>The image to display or null if there is no image</returns> protected internal Image DrawImage(object value, int rowIndex) { if(images == null) return null; int cellValue, bit, maxBit, idx, x = 0, count = images.Images.Count, width = images.ImageSize.Width; // Create the cell bitmap on first use if(cellImage == null) { cellImage = new Bitmap(((width + this.ImageSpacing) * count) - this.ImageSpacing, images.ImageSize.Height); imageStates = new List<bool>(); } // Reset the current states. Assume they are on by default. for(idx = 0; idx < count; idx++) if(idx < imageStates.Count - 1) imageStates[idx] = true; else imageStates.Add(true); // If the underlying value is a set of bit flags, use them to set the image state if(this.IsBitFlags && (value is int || value is short)) { if(value is int) { cellValue = (int)value; maxBit = 32; } else { cellValue = (short)value; maxBit = 16; } // Don't exceed the number of images in the list if(maxBit > count) maxBit = count; for(idx = 0, bit = 1; idx < maxBit; idx++, bit <<= 1) if((cellValue & bit) == 0) imageStates[idx] = false; } MapIndicatorEventArgs e = new MapIndicatorEventArgs(base.Index, rowIndex, value, imageStates); OnMapValueToIndicators(e); using(Graphics g = Graphics.FromImage(cellImage)) { // Draw each image using the appropriate state for(idx = 0; idx < count; idx++, x += width + this.ImageSpacing) if(imageStates[idx]) g.DrawImage(images.Images[idx], x, 0); else ControlPaint.DrawImageDisabled(g, images.Images[idx], x, 0, Color.Transparent); } return cellImage; }
/// <summary> /// This is used to draw the cell image on behalf of the cell /// </summary> /// <param name="value">The current cell value</param> /// <param name="rowIndex">The cell's row index</param> /// <returns>The image to display or null if there is no image</returns> protected internal Image DrawImage(object value, int rowIndex) { if (images == null) { return(null); } int cellValue, bit, maxBit, idx, x = 0, count = images.Images.Count, width = images.ImageSize.Width; // Create the cell bitmap on first use if (cellImage == null) { cellImage = new Bitmap(((width + this.ImageSpacing) * count) - this.ImageSpacing, images.ImageSize.Height); imageStates = new List <bool>(); } // Reset the current states. Assume they are on by default. for (idx = 0; idx < count; idx++) { if (idx < imageStates.Count - 1) { imageStates[idx] = true; } else { imageStates.Add(true); } } // If the underlying value is a set of bit flags, use them to set the image state if (this.IsBitFlags && (value is int || value is short)) { if (value is int) { cellValue = (int)value; maxBit = 32; } else { cellValue = (short)value; maxBit = 16; } // Don't exceed the number of images in the list if (maxBit > count) { maxBit = count; } for (idx = 0, bit = 1; idx < maxBit; idx++, bit <<= 1) { if ((cellValue & bit) == 0) { imageStates[idx] = false; } } } MapIndicatorEventArgs e = new MapIndicatorEventArgs(base.Index, rowIndex, value, imageStates); OnMapValueToIndicators(e); using (Graphics g = Graphics.FromImage(cellImage)) { // Draw each image using the appropriate state for (idx = 0; idx < count; idx++, x += width + this.ImageSpacing) { if (imageStates[idx]) { g.DrawImage(images.Images[idx], x, 0); } else { ControlPaint.DrawImageDisabled(g, images.Images[idx], x, 0, Color.Transparent); } } } return(cellImage); }