GroupBox vertical

Résolu
med_angelo Messages postés 21 Date d'inscription lundi 17 septembre 2007 Statut Membre Dernière intervention 30 septembre 2010 - 12 sept. 2008 à 13:00
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 - 14 sept. 2008 à 11:03
Salut tout le monde
Pour mon application j'ai un groupBox le texte de ce control est normalemnt en bleu horizontal et se trouve en haut a gauche et moi je voudrai que ce texte soit vertical et se trouvant en haut a gauche.
Merci d'avance

1 réponse

cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
14 sept. 2008 à 11:03
Bonjour,
Ce control ne permet pas cette manipulation, il faut donc la créer soit même. Ce n'est pas très compliqué, il suffit de créer un Control, et de faire un draw manuel. Un peu quelques choses comme ceci:

using

System.Windows.Forms;

using System.Drawing;

using System.Windows.Forms.VisualStyles;

namespace VerticalGroupBox
{
  
public
partial
class
VGroupBox :
GroupBox
   {
        
private
string _text =
null;
       
private
TxtLocation _textLocation =
TxtLocation.Top;

        
public VGroupBox()
       {
            InitializeComponent();
       }

      
public
enum
TxtLocation
      {
          Left,
          Right,
         Top,
         Bottom,
       }

      public
TxtLocation TextLocation
     {
          
get {
return
this._textLocation; }
          
set {
this._textLocation =
value; }
     }

     
public
override
string Text
     {
        
get {
return
this._text; }
        
set {
this._text =
value; }
     }

      protected
override
void OnPaint(
PaintEventArgs e)
     {
         
Graphics g = e.Graphics;

        
// Border
         GroupBoxState state =
base.Enabled ?
GroupBoxState.Normal :
GroupBoxState.Disabled;
        
TextFormatFlags flags =
TextFormatFlags.PreserveGraphicsTranslateTransform |
TextFormatFlags.PreserveGraphicsClipping |
TextFormatFlags.TextBoxControl |
TextFormatFlags.WordBreak;
       
GroupBoxRenderer.DrawGroupBox(g,
new
Rectangle(0, 0,
base.Width,
base.Height),
this.Text,
this.Font, flags, state);

       
StringFormat sf =
new
StringFormat();
        
// sf.Alignment = StringAlignment.Near;

        switch (
this._textLocation)
       {
         
case
TxtLocation.Bottom:
              // .......

              break;
       
case
TxtLocation.Left:
             // .......
            
sf.FormatFlags = StringFormatFlags.DirectionVertical;
             g.DrawString(
this._text,
this.Font,
new
SolidBrush(
Color.Black),
new
Point(10, 10), sf);
            
break;
       
case
TxtLocation.Right:
               sf.FormatFlags =
StringFormatFlags.DirectionVertical;
               // .......

             break;
       
case
TxtLocation.Top:
              // .......

             break;
        }
    }
  }
}

<hr />
-My Blog-
3
Rejoignez-nous