protected void RenderCacheImages() { CustomProgressBar.DisposeToNull(backgroundCacheImage); CustomProgressBar.DisposeToNull(overlayCacheImage); backgroundCacheImage = new Bitmap(Width, Height); using (Graphics backgroundCacheGraphics = Graphics.FromImage(backgroundCacheImage)) { // Render the background, here we pass the entire width of the progressbar as the distance value because we // always want the entire background to be drawn. Render(backgroundCacheGraphics, backgroundImage, backgroundDrawMethod, backgroundLeadingSize, backgroundTrailingSize, this.Width); } overlayCacheImage = new Bitmap(Width, Height); using (Graphics overlayCacheGraphics = Graphics.FromImage(overlayCacheImage)) { // Make sure that we retain our chroma key value by starting with a fully transparent overlay cache image #if PocketPC overlayCacheGraphics.FillRectangle(new SolidBrush(Color.Magenta), ClientRectangle); #else overlayCacheGraphics.FillRectangle(new SolidBrush(Color.Transparent), ClientRectangle); #endif // Render the overlay, this way we can get neat border on our progress bar (for example) Render(overlayCacheGraphics, overlayImage, overlayDrawMethod, overlayLeadingSize, overlayTrailingSize, this.Width); } }
private void ProgressBar_Resize(object sender, EventArgs e) { // // If the progressbar is resized we dump out current offscreen and set it to null, a new one // will then be created as the OnPaint method will request this if it is null. // CustomProgressBar.DisposeToNull(offscreenImage); CustomProgressBar.DisposeToNull(offscreen); DoLayout(); RenderCacheImages(); }