2009-03-10 10 views
1

私は次のカスタムコントロールを持ち、フォームに配置できます(AutoScrollをtrueに設定し、コントロールを左上、右上に固定)。スクロールバーがまだ削除された後に塗りつぶされます

フォームがコントロールに対して短すぎる場合、フォームはコントロールのサイズを正しく変更してスクロールバーを表示します。

閉じるグリフを使用してコントロールを閉じると、コントロールのサイズが変更され、スクロールバーが削除されますが、スクロールバーが描画されたままになることがあります。フォームが最小化されたり画面外に移動したりすると、残りのペイントが削除されます。

私はParent.Invalidateを試してきましたが、多くの点でそれを試してみましたが、役に立たなかったのです。助言がありますか? (VS 2008の標準を使用して)

alt text http://waltware.homedns.org/screenshot.jpg

using System; 
using System.ComponentModel; 
using System.Drawing; 
using System.Drawing.Drawing2D; 
using System.Windows.Forms; 



namespace GroupPanelTest 
{ 
    public class GroupPanel : GroupBox 
    { 
     #region Members 
     private const Int32 iHeaderHeight = 20; 
     private Int32 iFullHeight = 200; 

     private Boolean bClosed = false; 
     private Rectangle rectCloseGlyphBounds = Rectangle.Empty; 
     private Boolean bIsMoveOverCloseGlyph = false; 
     #endregion 

     #region Properties 
     [DefaultValue(false)] 
     public Boolean Closed 
     { 
      get 
      { 
       return (this.bClosed); 
      } 
      set 
      { 
       if (this.bClosed != value) 
       { 
        this.bClosed = value; 
        if (this.bClosed) 
        { 
         this.iFullHeight = base.Height; 
         base.Height = GroupPanel.iHeaderHeight; 
        } 
        else 
        { 
         base.Height = this.iFullHeight; 
        } 

        foreach (Control con in base.Controls) 
         con.Visible = !this.bClosed; 

        this.Invalidate(); 
       } 
      } 
     } 

     public new Int32 Height 
     { 
      get 
      { 
       return (base.Height); 
      } 
      set 
      { 
       if (value != base.Height) 
       { 
        if (this.Closed) 
        { 
         this.iFullHeight = value; 
        } 
        else 
        { 
         Int32 iOldHeight = base.Height; 
         base.Height = value; 
        } 
       } 
      } 
     } 

     [DefaultValue(typeof(Size), "350,200")] 
     public new Size Size 
     { 
      get 
      { 
       return (base.Size); 
      } 
      set 
      { 
       if (base.Size != value) 
       { 
        base.Size = value; 
        if (!this.Closed) 
         this.iFullHeight = value.Height; 
       } 
      } 
     } 

     [DefaultValue(typeof(Padding), "0,7,0,0")] 
     public new Padding Padding 
     { 
      get 
      { 
       return (base.Padding); 
      } 
      set 
      { 
       base.Padding = value; 
      } 
     } 
     #endregion 

     #region Construction 
     public GroupPanel() 
     { 
      SetStyle(ControlStyles.UserPaint, true); 
      SetStyle(ControlStyles.ResizeRedraw, true); 
      SetStyle(ControlStyles.AllPaintingInWmPaint, true); 
      SetStyle(ControlStyles.OptimizedDoubleBuffer, true); 
      SetStyle(ControlStyles.Selectable, true); 

      this.Size = new Size(350, 200); 
      this.Padding = new Padding(0, 7, 0, 0); // the groupbox will add to that 
      this.rectCloseGlyphBounds = new Rectangle(base.ClientSize.Width - 24, 2, 16, 16); 
     } 
     #endregion 

     #region Overrides 
     protected override void OnSizeChanged (EventArgs e) 
     { 
      this.rectCloseGlyphBounds = new Rectangle(base.ClientSize.Width - 24, 2, 16, 16); 
      base.OnSizeChanged(e); 
     } 

     protected override void OnPaint (PaintEventArgs e) 
     { 
      base.OnPaint(e); // we want all the delegates to receive the events, but we do this first so we can paint over it 

      Graphics g = e.Graphics; 

      g.FillRectangle(SystemBrushes.Window, this.ClientRectangle); 
      Rectangle rectTitle = new Rectangle(0, 0, this.ClientRectangle.Width, GroupPanel.iHeaderHeight); 
      g.FillRectangle(SystemBrushes.Control, rectTitle); 
      g.DrawString(this.Text, this.Font, SystemBrushes.ControlText, new PointF(5.0f, 3.0f)); 

      if (this.bIsMoveOverCloseGlyph) 
      { 
       g.FillRectangle(SystemBrushes.ButtonHighlight, this.rectCloseGlyphBounds); 
       Rectangle rectBorder = this.rectCloseGlyphBounds; 
       rectBorder.Inflate(-1, -1); 
       g.DrawRectangle(SystemPens.Highlight, rectBorder); 
      } 

      using (Pen pen = new Pen(SystemColors.ControlText, 1.6f)) 
      { 
       if (this.Closed) 
       { 
        g.DrawLine(pen, this.rectCloseGlyphBounds.Left + 3, this.rectCloseGlyphBounds.Top + 3, this.rectCloseGlyphBounds.Left + 8, this.rectCloseGlyphBounds.Top + 8); 
        g.DrawLine(pen, this.rectCloseGlyphBounds.Left + 13, this.rectCloseGlyphBounds.Top + 3, this.rectCloseGlyphBounds.Left + 8, this.rectCloseGlyphBounds.Top + 8); 

        g.DrawLine(pen, this.rectCloseGlyphBounds.Left + 3, this.rectCloseGlyphBounds.Top + 7, this.rectCloseGlyphBounds.Left + 8, this.rectCloseGlyphBounds.Top + 12); 
        g.DrawLine(pen, this.rectCloseGlyphBounds.Left + 13, this.rectCloseGlyphBounds.Top + 7, this.rectCloseGlyphBounds.Left + 8, this.rectCloseGlyphBounds.Top + 12); 
       } 
       else 
       { 
        g.DrawLine(pen, this.rectCloseGlyphBounds.Left + 3, this.rectCloseGlyphBounds.Top + 8, this.rectCloseGlyphBounds.Left + 8, this.rectCloseGlyphBounds.Top + 3); 
        g.DrawLine(pen, this.rectCloseGlyphBounds.Left + 13, this.rectCloseGlyphBounds.Top + 8, this.rectCloseGlyphBounds.Left + 8, this.rectCloseGlyphBounds.Top + 3); 

        g.DrawLine(pen, this.rectCloseGlyphBounds.Left + 3, this.rectCloseGlyphBounds.Top + 12, this.rectCloseGlyphBounds.Left + 8, this.rectCloseGlyphBounds.Top + 7); 
        g.DrawLine(pen, this.rectCloseGlyphBounds.Left + 13, this.rectCloseGlyphBounds.Top + 12, this.rectCloseGlyphBounds.Left + 8, this.rectCloseGlyphBounds.Top + 7); 
       } 
      } 
     } 

     protected override void OnMouseDown (MouseEventArgs e) 
     { 
      if (e.Button == MouseButtons.Left && this.rectCloseGlyphBounds.Contains(e.Location)) 
       this.Closed = !this.Closed; // close will call invalidate 
      base.OnMouseDown(e); 
     } 

     protected override void OnMouseMove (MouseEventArgs e) 
     { 
      this.bIsMoveOverCloseGlyph = this.rectCloseGlyphBounds.Contains(e.Location); 
      this.Invalidate(this.rectCloseGlyphBounds); 
      base.OnMouseMove(e); 
     } 
     #endregion 
    } 
} 
+0

あなたのスクリーンショットでは非常に奇妙なことがあります。グリフはスクロールバーの上に塗りつぶされましたか?それを追いかける。 –

答えて

0

あなたは所望の効果を得るためにControl.Invalidate後Control.Updateを()()を呼び出す必要があります。または単に.Refresh()を呼び出すだけで、あなたの人生を少し楽にしてください。

+0

私はそれを試しましたが、動作は変わりません。 –

+0

ええと...それは薬物がスクリーンから外れると消えてしまうので変だ。私がその動作を見るたびに、無効化/更新パスで修正されるケースがありました(これは基本的に、画面からもドラッグしたときに起こります)。私がそれを把握すれば私はポストバックします。 – colithium

関連する問題