Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Nytegard

.NET painting performance

This topic is 5225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Learning C# by writing a simple map editor. Now, part of the editor involves displaying a grid so I can see the tiles more easily. First off, here's my relevant code for the questions:
protected override void OnPaintBackground(PaintEventArgs pevent) 
		{ 
			//Do nothing

		} 

		private void FrmMap_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			int index;

			if(bmpbackBuffer == null) 

			{ 
				bmpbackBuffer = new Bitmap(this.ClientSize.Width,this.ClientSize.Height); 
			} 

			Graphics g_backbuf = Graphics.FromImage(bmpbackBuffer); 

			g_backbuf.Clear(Color.White);

			if(m_bGridLines == true)
			{

				for(index = 0; index <= (this.Width / 16); index++)
				{
					g_backbuf.DrawLine(System.Drawing.Pens.DarkSlateGray, index * 16, 0, index* 16, this.Bottom);
				}

				for(index = 0; index <= (this.Height / 16); index++)
				{
					g_backbuf.DrawLine(System.Drawing.Pens.DarkSlateGray, 0, index * 16, this.Right, index * 16);
				}
			}

			g_backbuf.Dispose(); 

			e.Graphics.DrawImageUnscaled(bmpbackBuffer,0,0); 
		}
 
A few quick questions: A) Any way to draw an inverse line in a managed environment? I want something like SetROP2(R2_NOT). I see DrawReversibleLine does something similar to what I want, but it seems I have to write an extended amount of code to make sure that the line doesn't go out of the correct child window. B) Why does commenting out g_backbuf.Clear(Color.White); slow down the program so badly? With the regular GDI, I would get a performance increase if I didn't bother ever to fill in the Client Rectangle. C) How could I speed it up? When dragging the window around, it slows down to an unbearable drag. I thought the above would double buffer, but I guess it's not, or its not doing it efficiently. [edited by - Nytegard on June 3, 2004 4:50:30 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You might want to read this: http://windowsforms.net/articles/windowsformspainting.aspx

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!