积极答复者
Graphics.DrawImage 画图 如何反复重新绘制?

问题
-
public int img { get { return imgstyle; } set { imgstyle=value; imgPicBox psBox = new imgPicBox(); psBox.Location = new Point(10, 10); psBox.Size = new Size(40, 40); psBox.Image2Location = new Point(25, 25); psBox.Image2size = new Size(15,15); psBox.Image1 = avatar.Image; if (imgstyle == 0) { psBox.Image2 = Properties.Resources.a; } else if (imgstyle == 1) { psBox.Image2 = Properties.Resources.b; } else if (imgstyle == 2) { psBox.Image2 = Properties.Resources.c; } else if (imgstyle == 3) { psBox.Image2 = Properties.Resources.d; } else if (imgstyle == 4) { psBox.Image2 = Properties.Resources.e; } else if (imgstyle == 5) { psBox.Image2 = Properties.Resources.f; } else { psBox.Image2 = null; } avatar.Visible = false; this.Controls.Add(psBox); //psBox.Invalidate(); psBox.Refresh(); } } public class imgPicBox : UserControl { public imgPicBox() { this.Image2Opacity = 1f; base.DoubleBuffered = true; } public Image Image1 { get; set; } public Image Image2 { get; set; } public Point Image2Location { get; set; } public float Image2Opacity { get; set; } public Size Image2size { get; set; } protected override void OnPaint(PaintEventArgs e) { if (Image1 != null) { e.Graphics.DrawImage(Image1, new Rectangle(0,0,40,40), new Rectangle(Point.Empty, Image1.Size), GraphicsUnit.Pixel); } if (Image2 != null) { ImageAttributes attr = new ImageAttributes(); attr.SetColorMatrix(new ColorMatrix() { Matrix33 = Image2Opacity }); e.Graphics.DrawImage(Image2, new Rectangle(Image2Location.X, Image2Location.Y, Image2size.Width, Image2size.Height), 0, 0, Image2size.Width, Image2size.Height, GraphicsUnit.Pixel, attr); } } }
尝试改变 img 的自定义值 的时候重新绘制图片 如何改变一次重新绘制一次?
当img 值为0的时候 绘制一次 再次改变img的值为1的时候 重新绘制一张图 但是试过很多方法 只有第一次起作用 再修改丝毫不起作用????
- 已编辑 ylzl 2016年9月12日 15:37