I have a PictureBox that draws an image and then a rectangle. However, annoyingly, any other window that I put over the rectangle causes it not to redraw. (I can cut out half of the rectangle by opening Notepad and placing it over half of it, or all of it by minimizing and then maximizing)
Here is my code:
Don't worry about the values of the coordinates or the NPC stuff. There must be something wrong with my ordering or my structuring of creating graphics specifically.
This function gets called on HandleScroll and Click for the picturebox, as well as on the form Resize. And, certainly enough, the rectangle comes back when any of these events are done. But why would the rectangle disappear and not the rest of the image? That's what bothers me.
If you would like to see more code just say so.
Thanks,
Scott
Here is my code:
Code:
private void Refresh_PictureBox() { Graphics g = pictureBox1.CreateGraphics(); g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, pictureBox1.Right - vScrollBar1.Width, pictureBox1.Bottom - hScrollBar1.Height), new Rectangle(hScrollBar1.Value, vScrollBar1.Value, pictureBox1.Right - vScrollBar1.Width, pictureBox1.Bottom - hScrollBar1.Height), GraphicsUnit.Pixel); foreach (NPC npc in NPCs) { if (npc.ID == NPCSelectedID) { Point p1 = new Point(npc.startx - hScrollBar1.Value, npc.starty - vScrollBar1.Value); g.DrawRectangle(new Pen(Color.Red), new Rectangle(p1, new Size(npc.width, npc.height))); } } pictureBox1.Update(); g.Dispose(); }
This function gets called on HandleScroll and Click for the picturebox, as well as on the form Resize. And, certainly enough, the rectangle comes back when any of these events are done. But why would the rectangle disappear and not the rest of the image? That's what bothers me.
If you would like to see more code just say so.
Thanks,
Scott
Comment