SidebarLibrary.WinControls.OutlookBar.DrawItem C# (CSharp) Method

DrawItem() private method

private DrawItem ( Graphics g, int index, Rectangle itemRect, bool hot, bool pressed, Rectangle targetRect, OutlookBarBand drawingBand ) : void
g System.Drawing.Graphics
index int
itemRect System.Drawing.Rectangle
hot bool
pressed bool
targetRect System.Drawing.Rectangle
drawingBand OutlookBarBand
return void
		void DrawItem(Graphics g, int index, Rectangle itemRect, bool hot, bool pressed, Rectangle targetRect, OutlookBarBand drawingBand)
		{
			OutlookBarBand band = bands[currentBandIndex];
			if (drawingBand != null)
				band = drawingBand;

			Point pt = new Point(0, 0);
			// Set clip region so that we don't draw outside the viewport
			Rectangle viewPortRect = GetViewPortRect();
			if (targetRect != Rectangle.Empty)
				viewPortRect = targetRect;

			using (Region clippingRegion = new Region(viewPortRect))
			{
				g.Clip = clippingRegion;
				// Clip the arrow buttons
				g.ExcludeClip(downArrowRect);
				g.ExcludeClip(upArrowRect);

				Color textColor = band.TextColor;
				Color backColor = band.Background;
				Color highLight = band.Background;

				if (ColorUtil.UsingCustomColor)
				{
					backColor = ColorUtil.VSNetControlColor;
					highLight = ColorUtil.VSNetControlColor;
				}

				if (hot)
				{
					backColor = ColorUtil.VSNetSelectionColor;
					highLight = ColorUtil.VSNetBorderColor;
				}

				if (pressed)
					backColor = ColorUtil.VSNetPressedColor;

				//john hatton jdh
				if (band.Items[index].Selected)
					highLight = Color.Blue;

				if (band.IconView == IconView.Large && band.LargeImageList != null)
				{
					Size largeImageSize = band.LargeImageList.ImageSize;
					pt.X = itemRect.Left + (viewPortRect.Width - largeImageSize.Width) / 2;
					pt.Y = itemRect.Top;

					Rectangle iconRect = new Rectangle(pt, largeImageSize);
					using (Brush b = new SolidBrush(backColor))
					{
						iconRect.Inflate(2, 2);
						if (backgroundBitmap != null)
						{
							g.DrawImage(backgroundBitmap, iconRect, iconRect, GraphicsUnit.Pixel);
							// If we have a background bitmap, draw the item background
							// only during the hot state
							if (hot)
							{
								g.FillRectangle(b, iconRect.Left, iconRect.Top,
									iconRect.Width, iconRect.Height);
							}
						}
						else
						{

							// If we don't have a background, always draw the
							// item backgound
							g.FillRectangle(b, iconRect.Left, iconRect.Top,
								iconRect.Width, iconRect.Height);
						}

						using (Pen p = new Pen(highLight))
						{
							if (backgroundBitmap == null || hot == true)
							{
								g.DrawRectangle(p, iconRect.Left, iconRect.Top, iconRect.Width - 1, iconRect.Height - 1);
							}

						}
					}

					// I dont' use the image list to do the drawing because cliping does not work
					if (band.Items[index].ImageIndex != -1 && band.LargeImageList != null)
					{
						// Only if we have a valid image index
						g.SmoothingMode = SmoothingMode.HighQuality;
						g.DrawImage(band.LargeImageList.Images[band.Items[index].ImageIndex], pt);
						g.SmoothingMode = SmoothingMode.Default;
					}

					// Draw the label
					int top = itemRect.Top + largeImageSize.Height + Y_LARGEICON_LABEL_OFFSET;
					Size textSize = GetLabelSize(g, band, index);
					int left = itemRect.Left + (viewPortRect.Width - textSize.Width) / 2;
					using (Brush b = new SolidBrush(textColor))
					{
						g.DrawString(band.Items[index].Text, Font, b, new Point(left, top));
					}

					// Reset clip region to the whole rectangle so that the arrows can be painted
					g.Clip = new Region(viewPortRect);
				}
				else if (band.IconView == IconView.Small && band.SmallImageList != null)
				{

					Size smallImageSize = band.SmallImageList.ImageSize;
					pt.X = itemRect.Left;
					pt.Y = itemRect.Top + (itemRect.Height - smallImageSize.Height) / 2;

					Rectangle iconRect = new Rectangle(pt, smallImageSize);
					using (Brush b = new SolidBrush(backColor))
					{
						iconRect.Inflate(1, 1);
						if (backgroundBitmap != null)
						{
							g.DrawImage(backgroundBitmap, iconRect, iconRect, GraphicsUnit.Pixel);
							// If we have a background bitmap, draw the item background
							// only during the hot state
							if (hot)
							{
								g.FillRectangle(b, iconRect.Left, iconRect.Top,
									iconRect.Width, iconRect.Height);
							}
						}
						else
						{
							// If we don't have a background, always draw the
							// item backgound
							g.FillRectangle(b, iconRect.Left, iconRect.Top,
								iconRect.Width, iconRect.Height);
						}

						using (Pen p = new Pen(highLight))
						{
							if (backgroundBitmap == null || hot == true)
							{
								g.DrawRectangle(p, iconRect.Left, iconRect.Top, iconRect.Width - 1, iconRect.Height - 1);
							}
						}
					}

					// I dont' use the image list to do the drawing because cliping does not work
					if (band.Items[index].ImageIndex != -1 && band.SmallImageList != null)
					{
						// Only if we have a valid image index
						g.DrawImage(band.SmallImageList.Images[band.Items[index].ImageIndex], pt);
					}

					// Draw the label
					Size labelSize = GetLabelSize(g, band, index);
					pt.X = pt.X + smallImageSize.Width + X_SMALLICON_LABEL_OFFSET;
					pt.Y = itemRect.Top + (itemRect.Height - labelSize.Height) / 2;
					using (Brush b = new SolidBrush(textColor))
					{
						g.DrawString(band.Items[index].Text, Font, b, pt);
					}
				}
			}
		}