2014-10-16 68 views
-1

我的程序有一个带有图片框的窗体,在这里我绘制了一些可视化图像。所以我做了refreshVisuals方法并在需要时应用它。但每当Form首次出现时,我会看到我的refreshVisuals()如何在picturebox上绘制正确的图片,然后backgroundColor或backgroundImage如何填充picturebox。在移动窗口或调整窗口大小后,我的可视化工具再次绘制正确的图片Color.Transparent作为背景颜色并没有帮助。如何使PictureBox在创建后不填充背景?

如何禁用背景填充?初始背景填充之后是否会发生一些事件?

public partial class Visuals: Form 
{ 
//something here 

public Visuals() 
{ 
    //some initials here 
    this.NeedRefreshPlease +=refreshVisuals; // my event, when something changes, works right. 
    this.Activated += refreshVisuals; 
    this.Move += refreshVisuals; 
    this.AutoSizeChanged += refreshVisuals; 
    this.Resize += refreshVisuals; 
    this.VisibleChanged += refreshVisuals; 
    this.Invalidated += refreshVisuals; 
    this.SizeChanged += refreshVisuals; 
    this.Shown += refreshVisuals; 
    //tried here almost every event, didn't work. 
} 

public void refreshVisuals(object sender, EventArgs e) 
{ 
    //actual drawing on Picturebox 
} 

}

+1

这是可怕的代码。可能是由使用CreateGraphics()引起的。停止使用它,它总是错误的,请使用图片框“Paint事件”。 – 2014-10-16 12:27:05

回答

0

可以使用SuspendLayout的控制。