TABPAGE STYLE VS2005

scoubidou944 Messages postés 714 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 19 janvier 2017 - 2 janv. 2005 à 14:04
scoubidou944 Messages postés 714 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 19 janvier 2017 - 2 janv. 2005 à 15:06
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/28351-tabpage-style-vs2005

scoubidou944 Messages postés 714 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 19 janvier 2017
2 janv. 2005 à 15:06
voici le code à rajouter juste après les variables dans HorizontalTabs (ligne 53)

#region Color
private Color m_oBackColorGradientDown;
private Color m_oBackColorGradientUp;
private Color m_oBackColorBorder;
private Color m_oColorLineSeparator;
private Color m_oColorSelection;

public Color BackColorGradientDown
{
get { return m_oBackColorGradientDown; }
set { m_oBackColorGradientDown = value; }
}
public Color BackColorGradientUp
{
get { return m_oBackColorGradientUp; }
set { m_oBackColorGradientUp = value; }
}
public Color BackColorBorder
{
get { return m_oBackColorBorder; }
set { m_oBackColorBorder = value; }
}
public Color ColorLineSeparator
{
get { return m_oColorLineSeparator; }
set { m_oColorLineSeparator = value; }
}
public Color SelectionColor
{
get { return m_oColorSelection; }
set { m_oColorSelection = value; }
}

void InitColors ()
{
m_oBackColorGradientUp = Color.FromArgb(245,250,245);
m_oBackColorGradientDown = Color.FromArgb(240,250,234);
m_oBackColorBorder = Color.FromArgb(109,139,164);
m_oColorLineSeparator = Color.FromArgb(232,231,223);
m_oColorSelection = Color.WhiteSmoke;
}
#endregion



Ligne 114 : ajouter l'appel dans le contructeur : this.InitColors ();

Ligne 362 : DrawTabCadre (), j'ai supprimé le tracage des elipses je trouvais ca pas beau

Voici la nouvelle méthode OnPaint:
protected override void OnPaint(PaintEventArgs e)
{
int nbTabsHide = 0;
Rectangle r = OrientationRectangle(this.ClientRectangle);

using (LinearGradientBrush br = new LinearGradientBrush (this.ClientRectangle, m_oBackColorGradientUp, m_oBackColorGradientDown, 90))
{
Matrix m = OrientationMatrix;
if (m != null)
e.Graphics.Transform = m;
e.Graphics.FillRectangle(br, r);
using (Pen pTour = new Pen(m_oBackColorBorder))
{
r = DisplayRectangle;

//le DisplayRectangle est déjà tourné
e.Graphics.ResetTransform();
//dessin du tour du tabpage
e.Graphics.DrawRectangle(pTour, r.X-1, r.Y-1, r.Width+1, r.Height+1);
if (m != null)
e.Graphics.Transform = m;
using (GraphicsPath path = TabsRegion)
{
pTour.Width = 2;
e.Graphics.DrawPath(pTour, path);
}
using (Pen pLine = new Pen(m_oColorLineSeparator, 1))
{
nbTabsHide = 0;
//dessin des lignes
for (int i =0; i < Count; i++)
{
if (!IsVisible(i))
{
nbTabsHide++;
continue;
}
//dessin de la ligne blanche au dessus
e.Graphics.DrawLine(Pens.White, new Point(FMargins, FMargins + (i - nbTabsHide) * FTabsHeight - 1), new Point(FTabsWidth, FMargins + (i - nbTabsHide) * FTabsHeight -1));
//dessin de la ligne grise au dessus
e.Graphics.DrawLine(pLine, new Point(FMargins, FMargins + (i - nbTabsHide) * FTabsHeight), new Point(FTabsWidth, FMargins + (i - nbTabsHide) * FTabsHeight));
//dessin de la ligne grise au dessous
e.Graphics.DrawLine(Pens.White, new Point(FMargins, FMargins + (i - nbTabsHide) * FTabsHeight + FTabsHeight-1), new Point(FTabsWidth, FMargins + (i - nbTabsHide) * FTabsHeight + FTabsHeight-1));
//dessin de la ligne grise au dessous
e.Graphics.DrawLine(pLine, new Point(FMargins, FMargins + (i - nbTabsHide) * FTabsHeight + FTabsHeight), new Point(FTabsWidth, FMargins + (i - nbTabsHide) * FTabsHeight + FTabsHeight));
}
}
nbTabsHide = 0;
for (int i = 0; i < Count; i++)
{
if (!IsVisible(i))
{
nbTabsHide++;
continue;
}
//dessin du selectionné
if (i == FSelectedIndex)
{
Rectangle rSel = new Rectangle(1, FTabsHeight * (i - nbTabsHide) + FMargins, FTabsWidth + FMargins-2, FTabsHeight);
e.Graphics.FillRectangle(new SolidBrush (this.SelectionColor), rSel);

this.DrawTabCadre(e.Graphics, i- nbTabsHide);
using (Pen pLine = new Pen(Color.FromArgb(173,139,164)))
{
e.Graphics.DrawLine(pLine, FTabsWidth + FMargins+1, FTabsHeight * (i - nbTabsHide) + FMargins, FTabsWidth + FMargins+1, FTabsHeight * ((i - nbTabsHide)+1) + FMargins);
}

}
if (i == FHoverIndex)
{
DrawTabCadre(e.Graphics, i - nbTabsHide);
}
//dessin du texte
Rectangle rTab = new Rectangle(FMargins, FMargins + 1 + (i - nbTabsHide) * FTabsHeight, FTabsWidth - 5, FTabsHeight-1);
bool defaultDrawing = true;
if (OnDrawTab != null)
{
DrawTabEventArgs ev = new DrawTabEventArgs(e.Graphics, rTab);
OnDrawTab(this, ev);
defaultDrawing = ev.DefaultDrawing;
}
if (defaultDrawing)
{
StringFormat sf = new StringFormat();
sf.Alignment = FTabControls[i].HorizontalTextAlignement;
sf.LineAlignment = FTabControls[i].VerticalTextAlignment;
e.Graphics.DrawString(FTabControls[i].Text, this.Font, Brushes.Black, rTab, sf);
}
}
}
}
}
scoubidou944 Messages postés 714 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 19 janvier 2017
2 janv. 2005 à 14:17
Je pense que vais rajotuer qql truc moi ;p

HorizontalTabs::OnPaint

y'a du codage en dur pour les couleurs, rohhhh C mal ca ;p
scoubidou944 Messages postés 714 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 19 janvier 2017
2 janv. 2005 à 14:04
Allez j'en rajotue ma couche ici.
Encore un controle que l'on peut classer dans la catégorie : Que Du bonheur.

- J'ai pu assigner ma couleur de fond par Page,
- l'image de fond ne marche pas mais si on en met une sur le parent, on a une transparence au niveau de la place restante dans les onglets
- pas de problème avec une page contenant une treeview et une listview avec splitter.
- par contre il manque la barre de défilement lorsque l'on a trop d'onglets.
- L'orientation vers le haut peut etre pratique parfois (si vers le bas ca marche, ca doit pas etre long de faire vers le haut ;op
- Je n'ai pas pu modifier la couleur des noms d'onglets (tjs en 243.250.241)

Mais comme d'hab, excellent travail
Rejoignez-nous