2009-09-07 10 views

Répondre

0

Les doesnt fenêtres groupbox ont une propriété de couleur de la bordure, donc cela signifie que vous devrez créer une nouvelle classe hériter de groupbox et créer votre propre propriété de couleur de bordure. voici le code dont vous aurez besoin;

public class MyGroupBox : GroupBox 
    { 
     private Color _borderColor = Color.Black; 

     public Color BorderColor 
     { 
      get { return this._borderColor; } 
      set { this._borderColor = value; } 
     } 

     protected override void OnPaint(PaintEventArgs e) 
     { 
      //get the text size in groupbox 
      Size tSize = TextRenderer.MeasureText(this.Text, this.Font); 

      Rectangle borderRect = e.ClipRectangle; 
      borderRect.Y = (borderRect.Y + (tSize.Height/2)); 
      borderRect.Height = (borderRect.Height - (tSize.Height/2)); 
      ControlPaint.DrawBorder(e.Graphics, borderRect, this._borderColor, ButtonBorderStyle.Solid); 

      Rectangle textRect = e.ClipRectangle; 
      textRect.X = (textRect.X + 6); 
      textRect.Width = tSize.Width; 
      textRect.Height = tSize.Height; 
      e.Graphics.FillRectangle(new SolidBrush(this.BackColor), textRect); 
      e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect); 
     } 
    } 

après avoir ajouté ce code à votre solution, cliquez construction de projet, puis MyGroupBox apparaîtra dans votre boîte à outils pour pouvoir utiliser

Questions connexes