Code:
public Form1()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.UpdateStyles();
for (int x = 0; x < gridx; x++) // set initial array to -1 ( for checking purposes)
for (int y = 0; y < gridy; y++)
Map[x, y] = -1;
splitContainer1.Panel2.Paint += painthandler;
ImgList.ImageSize = new Size(32, 32);
setup_tile_bar();
do_pictureboxs();
backg = new Bitmap(splitContainer1.Panel2.Width, splitContainer1.Panel2.Height);
temp = splitContainer1.Panel2.CreateGraphics();
//temp = Graphics.FromImage(backg);
updatemap();
foreach (var PictureBox in mypicturebox)
{
PictureBox.Click += new EventHandler(picClick); // setup eventhandlers for picture boxs
}
}
public void painthandler(object sender, PaintEventArgs e)
{
e.Graphics.Clear(Color.Red);
e.Graphics.DrawImage(backg, 0, 0); <-- i believe this is the problem here
}
public void updatemap()
{
//draw the grid
for (int i = 0; i < gridx + 1; i++)
temp.DrawLine(new Pen(Color.White), new Point(i * 32, 0), new Point(i * 32, (splitContainer1.Panel2.Height)));
for (int i = 0; i < gridy + 1; i++)
temp.DrawLine(new Pen(Color.White), new Point(0, i * 32), new Point((splitContainer1.Panel2.Width), i * 32));
// check map for values outside of current tileset and reset to picturebox 0
if (ImgList.Images.Count != 0)
{
for (int x = 0; x < gridx; x++) // overlay tile map onto grid
for (int y = 0; y < gridy; y++)
{
if (Map[x, y] >= ImgList.Images.Count)
Map[x, y] = 0; // clear the tile value if no tile exists to replace it
}
}
for (int x = 0; x < gridx; x++) // overlay tile map onto grid
{
for (int y = 0; y < gridy; y++)
{
imageval = Map[x, y];
if (imageval >= 0 && ImgList.Images.Count > 0)
temp.DrawImage(ImgList.Images[imageval], x * 32, y * 32);
}
}
if (dragging)
{
int tempstartx = rectstartx; // temp variables so as not to corrupt actual start and end co-ords!
int tempstarty = rectstarty;
int width = rectendx - rectstartx;
int height = rectendy - rectstarty;
if (rectstartx > rectendx)
width = rectstartx - rectendx;
if (rectstarty > rectendy)
height = rectstarty - rectendy;
if (rectstartx > rectendx) //swap start to end if end is less than start
{
tempstartx = rectendx;
}
if (rectstarty > rectendy)
{
tempstarty = rectendy;
}
temp.DrawRectangle(Pens.White, tempstartx, tempstarty, width, height);
}
this.Invalidate(); // invalidate area
this.Update(); // force a redraw
}
here are the relevant sections that deal with the drawing and updates.
hope this helps - it si definatley an issue where the rendered section is not being rendered back to panel2. but i cnat see where or why