2010-02-16 50 views
0

在我的工具中,我使用了一个面板来更改页面。每个页面都有自己的面板,当我更改页面时,我会将面板与控件一起发送。在我作为画布使用面板我有以下油漆事件:在某些情况下画的边框运行

private void panelContent_Paint(object sender, PaintEventArgs e) 
    { 
     e.Graphics.CompositingQuality = CompositingQuality.HighQuality; 
     e.Graphics.SmoothingMode = SmoothingMode.HighQuality; 

     // Paints a border around the panel to match the treeview control 
     e.Graphics.DrawRectangle(Pens.CornflowerBlue, 
      e.ClipRectangle.Left, 
      e.ClipRectangle.Top, 
      e.ClipRectangle.Width - 1, 
      e.ClipRectangle.Height - 1); 

     e.Graphics.Flush(); 

     base.OnPaint(e); 
    } 

这种方法基本上是平的面板围绕一个漂亮的边框,以便看起来更好。出于某种原因,当我在此面板上移动另一个窗体时,构成边框的线条开始运行一点。有时也会从边界划出小线。在整个面板重新绘制之前,问题只发生几秒钟。有什么我可以做,以防止这种情况发生?

回答

0

ClipRectangle告诉你需要重新绘制哪部分控件。如果你正在移动它,这可能会是你的对象和被移动的对象的交集。您可以使用此信息更有效地重新绘制您的控件。

您可能想要绘制从(0,0)到(panelContent.Width-1,panelContent.Height-1)的矩形。

+0

就像一个魅力: 私人无效panelContent_Paint(对象发件人,PaintEventArgs的E) { e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.DrawRectangle(Pens.CornflowerBlue, 0, 0, panelContent.Width - 1, panelContent.Height - 1); e.Graphics.Flush(); base.OnPaint(e); } 谢谢! – Icono123 2010-02-17 13:01:42

相关问题