Ce blog s'intéresse en particulier aux technologies suivantes :.NET, ASP.NET, C#, VB.NET, MS SQL, JQUERY, CSS ,HTML. Ici je vais essayer d'écrire sur les problèmes que nous rencontrons dans notre travail quotidien en particulier sur les problèmes pour lesquels la réponse est difficile à trouver sur l'Internet, je vais partager avec vous mes solutions et connaissances ... J'espère que ce sera un lieu utile pour vous tous .
Affichage des articles dont le libellé est C#. Afficher tous les articles
Affichage des articles dont le libellé est C#. Afficher tous les articles
vendredi 29 juin 2012
lundi 3 octobre 2011
Vertical TabControl C#
Vertical TabControl C#
TabControlExtender est une classe permettant de créer un TabControl avec une orientation vertical.![]() |
| VerticalTab C#.NET |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public class TabControlExtender : TabControl
{
private int _HeaderWidth;
private int _HeaderHeight;
private System.Drawing.ContentAlignment _HeaderAlignment;
private System.Windows.Forms.Padding _HeaderPadding;
private Font _HeaderFont;
private Color _HeaderBackColor;
private SolidBrush _HeaderBackBrush;
private Color _HeaderBorderColor;
private Pen _HeaderBackPen;
private Color _HeaderForeColor;
private SolidBrush _HeaderForeBrush;
private Color _HeaderSelectedBackColor;
private SolidBrush _HeaderSelectedBackBrush;
private Color _HeaderSelectedForeColor;
private Brush _HeaderSelectedForeBrush;
private Color _BackColor;
private System.Drawing.SolidBrush _BackBrush;
#region " Header Properties "
[System.ComponentModel.DefaultValue(100)]
public int HeaderWidth
{
get { return this._HeaderWidth; }
set
{
this._HeaderWidth = value;
this.ItemSize = new Size(this.ItemSize.Width, value);
}
}
[System.ComponentModel.DefaultValue(32)]
public int HeaderHeight
{
get { return this._HeaderHeight; }
set
{
this._HeaderHeight = value;
this.ItemSize = new Size(value, this.ItemSize.Height);
}
}
[System.ComponentModel.DefaultValue(typeof(System.Drawing.ContentAlignment), "ContentAlignment.MiddleLeft")]
public System.Drawing.ContentAlignment HeaderAlignment
{
get { return this._HeaderAlignment; }
set
{
this._HeaderAlignment = value;
this.Invalidate();
}
}
[System.ComponentModel.DefaultValue(typeof(System.Windows.Forms.Padding), "3,3,3,3")]
public System.Windows.Forms.Padding HeaderPadding
{
get { return this._HeaderPadding; }
set
{
this._HeaderPadding = value;
this.Invalidate();
}
}
[System.ComponentModel.DefaultValue(typeof(Color), "White")]
public Color HeaderBorderColor
{
get { return this._HeaderBorderColor; }
set
{
if (!(value == this._HeaderBorderColor))
{
this._HeaderBorderColor = value;
if (this._HeaderBackPen != null)
{
this._HeaderBackPen.Dispose();
this._HeaderBackPen = null;
}
this.Invalidate();
}
}
}
[System.ComponentModel.DefaultValue(typeof(Color), "LightGray")]
public Color HeaderBackColor
{
get { return this._HeaderBackColor; }
set
{
if (!(value == this._HeaderBackColor))
{
this._HeaderBackColor = value;
if (this._HeaderBackBrush != null)
{
this._HeaderBackBrush.Dispose();
this._HeaderBackBrush = null;
}
this.Invalidate();
}
}
}
private SolidBrush HeaderBackBrush
{
get
{
if (this._HeaderBackBrush == null)
{
this._HeaderBackBrush = new SolidBrush(this.HeaderBackColor);
}
return this._HeaderBackBrush;
}
}
private Pen HeaderPen
{
get
{
if (this._HeaderBackPen == null)
{
this._HeaderBackPen = new Pen(this.HeaderBorderColor);
}
return this._HeaderBackPen;
}
}
[System.ComponentModel.DefaultValue(typeof(Color), "Black")]
public Color HeaderForeColor
{
get { return this._HeaderForeColor; }
set
{
if (!(value == this._HeaderForeColor))
{
this._HeaderForeColor = value;
if (this._HeaderForeBrush != null)
{
this._HeaderForeBrush.Dispose();
this._HeaderForeBrush = null;
}
this.Invalidate();
}
}
}
private SolidBrush HeaderForeBrush
{
get
{
if (this._HeaderForeBrush == null)
{
this._HeaderForeBrush = new SolidBrush(this.HeaderForeColor);
}
return this._HeaderForeBrush;
}
}
[System.ComponentModel.DefaultValue(typeof(Color), "DarkGray")]
public Color HeaderSelectedBackColor
{
get { return this._HeaderSelectedBackColor; }
set
{
if (!(value == this._HeaderSelectedBackColor))
{
this._HeaderSelectedBackColor = value;
if (this._HeaderSelectedBackBrush != null)
{
this._HeaderSelectedBackBrush.Dispose();
this._HeaderSelectedBackBrush = null;
}
this.Invalidate();
}
}
}
private SolidBrush HeaderSelectedBackBrush
{
get
{
if (this._HeaderSelectedBackBrush == null)
{
this._HeaderSelectedBackBrush = new SolidBrush(this.HeaderSelectedBackColor);
}
return this._HeaderSelectedBackBrush;
}
}
[System.ComponentModel.DefaultValue(typeof(Color), "Black")]
public Color HeaderSelectedForeColor
{
get { return this._HeaderSelectedForeColor; }
set
{
if (!(value == this._HeaderSelectedForeColor))
{
this._HeaderSelectedForeColor = value;
this._HeaderSelectedForeBrush.Dispose();
this._HeaderSelectedForeBrush = null;
this.Invalidate();
}
}
}
private SolidBrush HeaderSelectedForeBrush
{
get
{
if (this._HeaderSelectedForeBrush == null)
{
this._HeaderSelectedForeBrush = new SolidBrush(this.HeaderSelectedForeColor);
}
return (SolidBrush)this._HeaderSelectedForeBrush;
}
}
public Font HeaderFont
{
get { return this._HeaderFont; }
set
{
this._HeaderFont = value;
this.Invalidate();
}
}
#endregion
[System.ComponentModel.DefaultValue(typeof(Color), "White")]
[System.ComponentModel.Browsable(true)]
public override Color BackColor
{
get { return this._BackColor; }
set
{
if (!(this._BackColor == value))
{
this._BackColor = value;
if (this._BackBrush != null)
{
this._BackBrush.Dispose();
this._BackBrush = null;
}
this.Invalidate();
}
}
}
private SolidBrush BackBrush
{
get
{
if (this._BackBrush == null)
{
this._BackBrush = new SolidBrush(this.BackColor);
}
return this._BackBrush;
}
}
public TabControlExtender()
{
this._HeaderWidth = 100;
this._HeaderHeight = 32;
this._HeaderAlignment = ContentAlignment.MiddleLeft;
this._HeaderPadding = new Padding(3);
this._BackColor = Color.White;
this._HeaderBorderColor = Color.White;
this._HeaderFont = this.Font;
this._HeaderForeColor = Color.Black;
this._HeaderBackColor = Color.DarkGray;
this._HeaderSelectedBackColor = Color.LightGray;
this._HeaderSelectedForeColor = Color.Black;
this.DrawMode = TabDrawMode.OwnerDrawFixed;
this.SizeMode = TabSizeMode.Fixed;
this.Alignment = TabAlignment.Left;
this.ItemSize = new Size(this.HeaderHeight, this.HeaderWidth);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Graphics g = default(Graphics);
g = e.Graphics;
g.FillRectangle(this.BackBrush, e.ClipRectangle);
// background
for (int i = 0; i <= this.TabPages.Count - 1; i++)
{
this.DrawTabButton(g, i);
this.DrawTabText(g, i);
}
}
private void DrawTabButton(Graphics g, int TabPageIndex)
{
Rectangle r = default(Rectangle);
// get the tab rectangle
r = this.GetTabRect(TabPageIndex);
// increase its width we dont want the background in between
r.Width = r.Width + 2;
// if first tab page
if (TabPageIndex == 0)
{
// reduce its height and move it a little bit lower
// since in tab control first tab button is displayed a little
// bit heigher
r.Height = r.Height - 2;
r.Y = r.Y + 2;
}
// if given tab button is selected
if (this.SelectedIndex == TabPageIndex)
{
// use selected properties
g.FillRectangle(this.HeaderSelectedBackBrush, r);
// if currently focused then draw focus rectangle
if (this.Focused)
{
System.Windows.Forms.ControlPaint.DrawFocusRectangle(g, new Rectangle(r.Left + 2, r.Top + 2, r.Width - 4, r.Height - 5));
}
// else (not the selected tab page)
}
else
{
g.FillRectangle(this.HeaderBackBrush, r);
}
// if first tab button
if (TabPageIndex == 0)
{
// draw a line on top
g.DrawLine(this.HeaderPen, r.Left, r.Top, r.Right, r.Top);
}
// line at left
g.DrawLine(this.HeaderPen, r.Left, r.Top, r.Left, r.Bottom - 1);
// line at bottom
g.DrawLine(this.HeaderPen, r.Left, r.Bottom - 1, r.Right, r.Bottom - 1);
// no line at right since we want to give an effect of
// pages
}
private void DrawTabText(Graphics g, int TabPageIndex)
{
int iX = 0;
int iY = 0;
string sText = null;
SizeF sizeText = default(SizeF);
Rectangle rectTab = default(Rectangle);
// get tab button rectangle
rectTab = this.GetTabRect(TabPageIndex);
// get text
sText = this.TabPages[TabPageIndex].Text ;
// measure the size of text
sizeText = g.MeasureString(sText, this.HeaderFont);
// check text alignment
switch (this.HeaderAlignment)
{
case ContentAlignment.MiddleLeft:
case ContentAlignment.BottomLeft:
case ContentAlignment.TopLeft:
iX = rectTab.Left + this.HeaderPadding.Left;
break;
case ContentAlignment.MiddleRight:
case ContentAlignment.BottomRight:
case ContentAlignment.TopRight:
iX = rectTab.Right - Convert.ToInt32(sizeText.Width) - this.HeaderPadding.Right;
break;
case ContentAlignment.MiddleCenter:
case ContentAlignment.BottomCenter:
case ContentAlignment.TopCenter:
iX = rectTab.Left + (rectTab.Width - this.HeaderPadding.Left - this.HeaderPadding.Right - Convert.ToInt32(sizeText.Width)) / 2;
break;
}
switch (this.HeaderAlignment)
{
case ContentAlignment.TopLeft:
case ContentAlignment.TopCenter:
case ContentAlignment.TopRight:
iY = rectTab.Top + this.HeaderPadding.Top;
break;
case ContentAlignment.BottomLeft:
case ContentAlignment.BottomCenter:
case ContentAlignment.BottomRight:
iY = rectTab.Bottom - Convert.ToInt32(sizeText.Height) - this.HeaderPadding.Bottom;
break;
case ContentAlignment.MiddleCenter:
case ContentAlignment.MiddleLeft:
case ContentAlignment.MiddleRight:
iY = rectTab.Top + (rectTab.Height - this.HeaderPadding.Top - Convert.ToInt32(sizeText.Height)) / 2;
break;
}
// if selected tab button
if (this.SelectedIndex == TabPageIndex)
{
g.DrawString(sText, this.HeaderFont, this.HeaderSelectedForeBrush, iX, iY);
}
else
{
g.DrawString(sText, this.HeaderFont, this.HeaderForeBrush, iX, iY);
}
}
}
Libellés :
.NET Controls,
C#
mardi 2 août 2011
Générer un rapport en utilisant Crystal Reports dans Visual Studio 2010
Générer un rapport en utilisant Crystal Reports dans Visual Studio 2010
Commençons par créer un nouveau site Web dans Visual studio 2010. Voir l'écran suivantConformément à la figure 1 de créer un nouveau site Web dans VS2010 et l'a nommé selon votre choix. Maintenant laissez-moi vous montrer la structure de la table base de données.
![]() |
| Figure 2 |
Figure ci-dessus montre la structure de la table db. Et figure ci-dessous (figure 3) va vous montrer quelques exemples de données dans la table
![]() |
| Figure 3 |
Ci-dessous figure le processus de vous montrer comment créer un fichier XML Shema(Dataset)
Pour ajouter un fichier DataSet, cliquez sur l'Explorateur de solutions -> clic droit sur le projet -> cliquer sur Ajouter un nouvel élément et ensuite il va vous montrer ci-dessous l'écran.
![]() |
| Figure 4 |
Cliquez sur le bouton OK afin qu'il vous demandera de confirmer à mettre ce fichier dans le dossier App_Code vous suffit de cliquer sur OK et que ce fichier sera ouvert dans l'écran comme écran vide.
Maintenant nous allons ajouter un blanc DataTable vers ce fichier XSD. Juste un clic droit sur le fichier et sélectionnez Ajouter -> DataTable. Il va ajouter une DataTable1 à l'écran. La figure 5 montre comment ajouter DataTable xsd.
![]() |
| Figure 5 |
C'est tout. Création d'un fichier XSD qui a été fait. Nous allons maintenant passer à créer la conception de Crystal report.
Il suffit de cliquer sur le Solution Explorer -> clic droit sur le nom du projet et sélectionnez Crystal Reports. Nommez selon votre choix et cliquez sur le bouton Ajouter
Figure 7 va vous montrer le processus de création de Crystal report.
![]() |
| Figure 8 |
![]() |
| Figure 9 |
Il suffit de cliquer le bouton OK pour continuer. Il vous mènera à la figure 9
Figure 11
Code Default.aspx
Résultat:
Libellés :
.NET,
C#,
Crystal Report,
Visual Studio 2010
Inscription à :
Articles (Atom)











