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

DrawBackground() private method

private DrawBackground ( Graphics g ) : void
g System.Drawing.Graphics
return void
		void DrawBackground(Graphics g)
		{
			Rectangle rc = ClientRectangle;
			// If we don't have any bands, just fill the rectangle
			// with the System Control Color
			if ( bands.Count == 0 || currentBandIndex == -1 )
			{
				g.FillRectangle(SystemBrushes.Control, rc);
				return;
			}

			if ( backgroundBitmap == null )
			{
				if ( currentBandIndex >= 0 && bands[currentBandIndex] != null )
				{
					using ( SolidBrush b = new SolidBrush(bands[currentBandIndex].Background) )
					{
						// If there is a child control clip the area where the child
						// control will be drawn to avoid flickering
						if ( HasChild() )
						{
							Rectangle clipRect = GetViewPortRect();
							g.ExcludeClip(clipRect);
						}
						g.FillRectangle(b, rc);
					}
				}
			}
			else
			{
				// Draw custom background bitmap
				// -- I don't know why but the bitmap is not painted properly if using the right size
				// I use the WindowsAPI to work around the problem
				GDIUtil.StrechBitmap(g, rc, backgroundBitmap);

				if ( needBackgroundBitmapResize )
				{
					needBackgroundBitmapResize = false;
					backgroundBitmap = GDIUtil.GetStrechedBitmap(g, rc, backgroundBitmap);
				}
			}

		}