Reputation: 1891
I have never really had to worry about how "pretty" my programs are before but I'm working on something for marketing now.... Anyways I imagine this is pretty simple but I can't seem to figure out why this isn't working. Basically I have a panel with a bunch of picture boxes in it and I am drawing colored rectangles behind them to create a pseudo "frame" around the photos. It has a different frame based on whether or not the photo is selected. The default selected photo is in position 0 and on the first time it paints everything looks great. But when the selection is changed, the paint event fires and nothing changes. Here's the code:
private void panelPicSet_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(panelPicSet.BackColor);
foreach (PictureBox picBox in panelPicSet.Controls)
{
if (picBox == selectedPhoto.PictureBox)
g.FillRectangle(new SolidBrush(Color.FromArgb(53, 73, 106)), new Rectangle(new Point(picBox.Location.X - 4, picBox.Location.Y - 4), new Size(picBox.Width + 8, picBox.Height + 8)));
if (picBox == hoveredPicBox)
g.FillRectangle(new SolidBrush(Color.FromArgb(53, 73, 106)), new Rectangle(new Point(picBox.Location.X - 2, picBox.Location.Y - 2), new Size(picBox.Width + 4, picBox.Height + 4)));
else
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 232, 166)), new Rectangle(new Point(picBox.Location.X - 2, picBox.Location.Y - 2), new Size(picBox.Width + 4, picBox.Height + 4)));
}
}
Upvotes: 0
Views: 413
Reputation: 1891
Like I suspected it was an easy answer. I had to call panelPicSet.Invalidate()
in the click and mouse enter/ leave events. I had assumed that clearing the graphics object in the paint event was performing the same function but apparently not.
Upvotes: 1