Microsoft KB Archive/834457

= BUG: You cannot use the Graphics.DrawXxxx methods to draw on a surface that is created by using the Graphics.FromImage method in the .NET Framework 1.0 or the .NET Framework 1.1 =

Article ID: 834457

Article Last Modified on 12/14/2004

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-





SYMPTOMS
The Graphics.Draw  methods in the Microsoft .NET Framework do not draw when you do the following:
 * You create a Graphics object by using the Graphics.FromImage method on a loaded bitmap.
 * Then you use the Graphics.Draw  methods to draw on top of the bitmap.

The bitmap is also reloaded.



WORKAROUND
To work around this problem, use the Bitmap.MakeTransparent method. To do this, locate the following line of code in step 2 of the &quot;Steps to reproduce the behavior section&quot;: Bitmap b = new Bitmap(BitmapPath); Under this line of code, add the following code: b.MakeTransparent(Color.FromArgb(0,0,0));



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the behavior
 Start Microsoft Visual Studio .NET, and then create a Microsoft Windows application by using Microsoft Visual C# .NET.  Replace the code in Form1.cs with the following code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;

namespace WindowsApplication3 {   public class Form1 : System.Windows.Forms.Form {       private System.ComponentModel.Container components = null;

public Form1 {           InitializeComponent;

//TODO: Replace BitmapPath with the path of your bitmap. Bitmap b = new Bitmap(BitmapPath); Graphics gb = Graphics.FromImage(b);

Rectangle rBounds = new Rectangle( 0, 0, b.Width, b.Height); gb.DrawRectangle(Pens.Purple, rBounds); gb.DrawEllipse(Pens.Yellow, rBounds); gb.DrawLine(Pens.Red, 0, 0, b.Width, b.Height); gb.Dispose;

Point p = new Point(0,0);

this.ClientSize = b.Size; Graphics g = this.CreateGraphics; this.Show; g.DrawImage(b, p); g.Dispose; }

protected override void Dispose( bool disposing ) {           if( disposing ) {               if (components != null) {                   components.Dispose; }           }            base.Dispose( disposing ); }

#region Windows Form Designer generated code ///        /// Required method for Designer support - do not modify /// the contents of this method with the code editor. ///        private void InitializeComponent {           this.components = new System.ComponentModel.Container; this.Size = new System.Drawing.Size(300,300); this.Text = &quot;Form1&quot;; }       #endregion

[STAThread] static void Main {           Application.Run(new Form1); }   } }  Modify the code accordingly where you see the TODO comment. Press CTRL+F5 to run the application.

You see the result that is described in the &quot;Symptoms&quot; section.

Keywords: kbtshoot kbwindowsforms kbgdi KB834457

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.