Color.FromArgb, méthode (Int32, Int32, Int32, Int32) (System.Drawing)

Bibliothèque de classes .NET Framework 
Color.FromArgb, méthode (Int32, Int32, Int32, Int32) 

Crée une structure Color à partir des valeurs des quatre composants ARVB (alpha, rouge, vert et bleu). Bien que cette méthode permette de passer une valeur 32 bits pour chaque composant, leur valeur est limitée à 8 bits.

Espace de noms : System.Drawing
Assembly : System.Drawing (dans system.drawing.dll)

SyntaxeSyntaxe


Visual Basic (Déclaration)
Public Shared Function FromArgb ( _
    alpha As Integer, _
    red As Integer, _
    green As Integer, _
    blue As Integer _
) As Color


Visual Basic (Utilisation)
Dim alpha As Integer
Dim red As Integer
Dim green As Integer
Dim blue As Integer
Dim returnValue As Color

returnValue = Color.FromArgb(alpha, red, green, blue)


C#
public static Color FromArgb (
    int alpha,
    int red,
    int green,
    int blue
)


C++
public:
static Color FromArgb (
    int alpha, 
    int red, 
    int green, 
    int blue
)


J#
public static Color FromArgb (
    int alpha, 
    int red, 
    int green, 
    int blue
)


JScript
public static function FromArgb (
    alpha : int, 
    red : int, 
    green : int, 
    blue : int
) : Color

Paramètres

alpha

Composant alpha. Les valeurs autorisées sont comprises entre 0 et 255.

red

Composant rouge. Les valeurs autorisées sont comprises entre 0 et 255.

green

Composant vert. Les valeurs autorisées sont comprises entre 0 et 255.

blue

Composant bleu. Les valeurs autorisées sont comprises entre 0 et 255.

Valeur de retour

Color créé par cette méthode.
ExceptionsExceptions
Type d'exceptionCondition

ArgumentException

alpha, red, green ou blue est inférieur à 0 ou supérieur à 255.

ExempleExemple

L'exemple de code suivant est destiné à être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du gestionnaire d'événements Paint. Le code exécute les actions suivantes :

  • Crée trois pinceaux de couleur différente. Chaque structure Color servant à la création d'un pinceau est créée à partir des valeurs des quatre composants (alpha, rouge, vert, bleu).

  • Positionne trois cercles à l'aide d'un triangle imaginaire.

  • Peint trois cercles qui se chevauchent à l'aide de trois pinceaux différents, en centrant chaque cercle sur un vertex différent du triangle.



Visual Basic
Public Sub FromArgb1(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics

    ' Transparent red, green, and blue brushes.
    Dim trnsRedBrush As New SolidBrush(Color.FromArgb(120, 255, 0, 0))
    Dim trnsGreenBrush As New SolidBrush(Color.FromArgb(120, 0, _
    255, 0))
    Dim trnsBlueBrush As New SolidBrush(Color.FromArgb(120, 0, 0, 255))

    ' Base and height of the triangle that is used to position the
    ' circles. Each vertex of the triangle is at the center of one of
    ' the 3 circles. The base is equal to the diameter of the circle.
    Dim triBase As Single = 100
    Dim triHeight As Single = CSng(Math.Sqrt((3 * (triBase * _
    triBase) / 4)))

    ' Coordinates of first circle's bounding rectangle.
    Dim x1 As Single = 40
    Dim y1 As Single = 40

    ' Fill 3 over-lapping circles. Each circle is a different color.
    g.FillEllipse(trnsRedBrush, x1, y1, 2 * triHeight, 2 * triHeight)
    g.FillEllipse(trnsGreenBrush, x1 + triBase / 2, y1 + triHeight, _
    2 * triHeight, 2 * triHeight)
    g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2 * triHeight, _
    2 * triHeight)
End Sub


C#
public void FromArgb1(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
             
    // Transparent red, green, and blue brushes.
    SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(120, 255, 0, 0));
    SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(120, 0, 255, 0));
    SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(120, 0, 0, 255));
             
    // Base and height of the triangle that is used to position the
    // circles. Each vertex of the triangle is at the center of one of the
    // 3 circles. The base is equal to the diameter of the circles.
    float   triBase = 100;
    float   triHeight = (float)Math.Sqrt(3*(triBase*triBase)/4);
             
    // Coordinates of first circle's bounding rectangle.
    float   x1 = 40;
    float   y1 = 40;
             
    // Fill 3 over-lapping circles. Each circle is a different color.
    g.FillEllipse(trnsRedBrush, x1, y1, 2*triHeight, 2*triHeight);
    g.FillEllipse(trnsGreenBrush, x1 + triBase/2, y1 + triHeight,
        2*triHeight, 2*triHeight);
    g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2*triHeight, 2*triHeight);
}


C++
void FromArgb1( PaintEventArgs^ e )
{
   Graphics^ g = e->Graphics;

   // Transparent red, green, and blue brushes.
   SolidBrush^ trnsRedBrush = gcnew SolidBrush( Color::FromArgb( 120, 255, 0, 0 ) );
   SolidBrush^ trnsGreenBrush = gcnew SolidBrush( Color::FromArgb( 120, 0, 255, 0 ) );
   SolidBrush^ trnsBlueBrush = gcnew SolidBrush( Color::FromArgb( 120, 0, 0, 255 ) );

   // Base and height of the triangle that is used to position the
   // circles. Each vertex of the triangle is at the center of one of the
   // 3 circles. The base is equal to the diameter of the circles.
   float triBase = 100;
   float triHeight = (float)Math::Sqrt( 3 * (triBase * triBase) / 4 );

   // Coordinates of first circle's bounding rectangle.
   float x1 = 40;
   float y1 = 40;

   // Fill 3 over-lapping circles. Each circle is a different color.
   g->FillEllipse( trnsRedBrush, x1, y1, 2 * triHeight, 2 * triHeight );
   g->FillEllipse( trnsGreenBrush, x1 + triBase / 2, y1 + triHeight, 2 * triHeight, 2 * triHeight );
   g->FillEllipse( trnsBlueBrush, x1 + triBase, y1, 2 * triHeight, 2 * triHeight );
}


J#
public void FromArgb1(PaintEventArgs e)
{
    Graphics g = e.get_Graphics();

    // Transparent red, green, and blue brushes.
    SolidBrush trnsRedBrush = new SolidBrush(
        Color.FromArgb(120, 255, 0, 0));
    SolidBrush trnsGreenBrush = new SolidBrush(
        Color.FromArgb(120, 0, 255, 0));
    SolidBrush trnsBlueBrush = new SolidBrush(
        Color.FromArgb(120, 0, 0, 255));

    // Base and height of the triangle that is used to position the
    // circles. Each vertex of the triangle is at the center of one of the
    // 3 circles. The base is equal to the diameter of the circles.
    float triBase = 100;
    float triHeight = (float)(Math.sqrt((3 * (triBase * triBase) / 4)));

    // Coordinates of first circle's bounding rectangle.
    float x1 = 40;
    float y1 = 40;

    // Fill 3 over-lapping circles. Each circle is a different color.
    g.FillEllipse(trnsRedBrush, x1, y1, 2 * triHeight, 2 * triHeight);
    g.FillEllipse(trnsGreenBrush, x1 + triBase / 2, y1 + triHeight, 
        2 * triHeight, 2 * triHeight);
    g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 
        2 * triHeight, 2 * triHeight);
} //FromArgb1
Plates-formesPlates-formes

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

Informations de versionInformations de version

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0
Voir aussiVoir aussi

Ces informations proviennent du site de http://msdn2.microsoft.com
Source de cette page : http://msdn2.microsoft.com/fr-fr/library/at1k42eh.aspx

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

10 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-6914
Document créé le 06/11/06 23:33, dernière modification le Vendredi 17 Juin 2011, 12:11
Source du document imprimé : http://www.gaudry.be/dotnet-rf-at1k42eh.html Document affiché 3 fois ce mois de Mai.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,64 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Où serait le mérite, si les héros n'avaient jamais peur?

Alphonse Daudet [Extrait de Tartarin de Tarascon]
 
l'infobrol
Nous sommes le Jeudi 31 Mai 2012, 00:58, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)