Results 1 to 3 of 3

Thread: [2.0] Detecting what area can be painted

  1. #1

    Thread Starter
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    [2.0] Detecting what area can be painted

    I am using this.Invalidate(new Rectangle(x, y, width, height));

    If I have my paint event, how can I detect what is the area to be drawn into?

    Code:

    Code:
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                //the if is what I am trying to do to detect if I am drawing into the whole screen... (like just calling me.Refresh())
    			if (e.Graphics.ClipBounds.X == this.Bounds.Width && e.Graphics.ClipBounds.Y == this.Bounds.Height)
    			{
    				for (int i = 0; i < formTilesX; i++)
    				{
    					for (int k = 0; k < formTilesY; k++)
    					{
    						if ((k * gridWidth) < (((playerX + formTilesX) * gridWidth) + gridWidth) && (i * gridHeight) < (((playerY + formTilesY) * gridHeight)) + gridHeight)
    						{
    
    							Bitmap bmp = new Bitmap(images[currentGrid[i, k]]);
    							e.Graphics.DrawImage(bmp, new Point(k * gridWidth, i * gridHeight));
    							bmp.Dispose();
    							bmp = null;
    						}
    					}
    				}
    			}
    			Bitmap playerBmp = new Bitmap(Resources.fighter);
    			e.Graphics.DrawImage(playerBmp, new Point(playerX * gridWidth, playerY * gridHeight));
    			playerBmp.Dispose();
    			playerBmp = null;
    			//HighlightTile(e);
    		}
    Any idea's?

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Detecting what area can be painted

    You don't. You just draw everything. The system then decides what part of that drawing will actually be painted to the screen based on what has been invalidated. It's not your logic that is time consuming. It's actually pushing the pixels to the screen that's the slow part, and the system is responsible for managing that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2.0] Detecting what area can be painted

    So the big for loop won't slow me down much?

    well, Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width