Original Post
HI guys its me again , im now porting my picturebox based map editor to a GDI+ environment. what Im trying to do right now is to highlight with a white square the cell where the mouse cursor is hovering Ive been reading everywhere that I should do all my painting in the paint event , so what Im doing is setting a boolean to true in the mousemove event then the paint even reads this value and decides to paint a square brush , but sadly at runtime nothing shows up ive tried many things but I think ive run out of options help me out pls! [/source]
[SOURCE]
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (tile_palette != null)
{
Pen highlight = new Pen(Color.White, 5.0f);
Pen grid = new Pen(Color.Black, 1.0f);
Bitmap curBitmap = new Bitmap(panel1.ClientRectangle.Width, panel1.ClientRectangle.Height);
Graphics back_buffer = Graphics.FromImage(curBitmap);
Graphics front_buffer = panel1.CreateGraphics();
back_buffer.TranslateTransform(this.panel1.AutoScrollPosition.X, this.panel1.AutoScrollPosition.Y);
// BACKBUFFER DRAWING
// Draw Image
back_buffer.DrawImageUnscaled(tile_palette.GetImage(), 0, 0);
// Draw Grid
for (int id_x = 0; id_x <= this.tile_palette.GetImage().Width; id_x += this.tile_palette.GetGridSize())
{
back_buffer.DrawLine(grid, new Point(id_x, 0), new Point(id_x, this.tile_palette.GetImage().Height));
}
for (int id_y = 0; id_y <= this.tile_palette.GetImage().Height; id_y += this.tile_palette.GetGridSize())
{
back_buffer.DrawLine(grid, new Point(0, id_y), new Point(this.tile_palette.GetImage().Width, id_y));
}
if (mouse_data.hover)
{
// Highlight selected cell
if (this.tile_palette.GetSelectedCell(mouse_data.location).Size.Width != 0)
{
//e.DrawRectangle(rectangle, this.tile_palette.GetSelectedCell(r.Location));
back_buffer.DrawRectangle(highlight, tile_palette.GetSelectedCell(mouse_data.location));
}
mouse_data.hover = false;
this.Invalidate();
}
// Present and Dispose
front_buffer.DrawImageUnscaled(curBitmap, 0,0);
// Dispose objects
front_buffer.Dispose();
back_buffer.Dispose();
grid.Dispose();
highlight.Dispose();
}
}// End Paint event
[/SOURCE]