2010-02-16 45 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

相關問題