[英]Simple graphic problem
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.默认选择的照片在 position 0 中,第一次绘制时一切看起来都很棒。 But when the selection is changed, the paint event fires and nothing changes. 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)));
}
}
Like I suspected it was an easy answer.就像我怀疑这是一个简单的答案。 I had to call panelPicSet.Invalidate()
in the click and mouse enter/ leave events.我必须在单击和鼠标进入/离开事件中调用panelPicSet.Invalidate()
。 I had assumed that clearing the graphics object in the paint event was performing the same function but apparently not.我曾假设在绘图事件中清除图形 object 正在执行相同的 function 但显然不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.