Assembly : System.Drawing (dans system.drawing.dll)
SyntaxePublic Shared Function FromArgb ( _ red As Integer, _ green As Integer, _ blue As Integer _ ) As Color
Dim red As Integer Dim green As Integer Dim blue As Integer Dim returnValue As Color returnValue = Color.FromArgb(red, green, blue)
public static Color FromArgb ( int red, int green, int blue )
public: static Color FromArgb ( int red, int green, int blue )
public static Color FromArgb ( int red, int green, int blue )
public static function FromArgb ( red : int, green : int, blue : int ) : Color
Paramètres
- red
Valeur du composant rouge du nouveau Color. Les valeurs autorisées sont comprises entre 0 et 255.
- green
Valeur du composant vert du nouveau Color. Les valeurs autorisées sont comprises entre 0 et 255.
- blue
Valeur du composant bleu du nouveau Color. Les valeurs autorisées sont comprises entre 0 et 255.
Valeur de retour
Color créé par cette méthode.
ExempleL'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 des structures Color à partir des valeurs des trois composants de couleur (rouge, vert et bleu). Trois structures Color sont créées, à raison d'une par couleur primaire.
-
Parcourt une plage de valeurs alpha, modifiant la valeur alpha d'une couleur.
-
Durant chaque itération, affecte la couleur modifiée à la couleur d'un pinceau et peint un rectangle pour afficher cette couleur.
-
Répète les étapes 2 et 3 pour chaque couleur primaire.
La valeur alpha n'est jamais entièrement opaque et les rectangles se chevauchent, produisant des effets de fusion de couleurs.
Public Sub FromArgb2(ByVal e As PaintEventArgs) Dim g As Graphics = e.Graphics ' Opaque colors (alpha value defaults to 255 -- max value). Dim red As Color = Color.FromArgb(255, 0, 0) Dim green As Color = Color.FromArgb(0, 255, 0) Dim blue As Color = Color.FromArgb(0, 0, 255) ' Solid brush initialized to red. Dim myBrush As New SolidBrush(red) Dim alpha As Integer ' x coordinate of first red rectangle. Dim x As Integer = 50 ' y coordinate of first red rectangle. Dim y As Integer = 50 ' Fill rectangles with red, varying the alpha value from 25 to 250. For alpha = 25 To 250 Step 25 myBrush.Color = Color.FromArgb(alpha, red) g.FillRectangle(myBrush, x, y, 50, 100) g.FillRectangle(myBrush, x, y + 250, 50, 50) x += 50 Next alpha ' x coordinate of first green rectangle. x = 50 ' y coordinate of first green rectangle. y += 50 ' Fill rectangles with green, varying alpha value from 25 to 250. For alpha = 25 To 250 Step 25 myBrush.Color = Color.FromArgb(alpha, green) g.FillRectangle(myBrush, x, y, 50, 150) x += 50 Next alpha ' x coordinate of first blue rectangle. x = 50 ' y coordinate of first blue rectangle. y += 100 ' Fill rectangles with blue, varying alpha value from 25 to 250. For alpha = 25 To 250 Step 25 myBrush.Color = Color.FromArgb(alpha, blue) g.FillRectangle(myBrush, x, y, 50, 150) x += 50 Next alpha End Sub
public void FromArgb2(PaintEventArgs e) { Graphics g = e.Graphics; // Opaque colors (alpha value defaults to 255 -- max value). Color red = Color.FromArgb(255, 0, 0); Color green = Color.FromArgb(0, 255, 0); Color blue = Color.FromArgb(0, 0, 255); // Solid brush initialized to red. SolidBrush myBrush = new SolidBrush(red); int alpha; // x coordinate of first red rectangle int x = 50; // y coordinate of first red rectangle int y = 50; // Fill rectangles with red, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { myBrush.Color = Color.FromArgb(alpha, red); g.FillRectangle(myBrush, x, y, 50, 100); g.FillRectangle(myBrush, x, y + 250, 50, 50); x += 50; } // x coordinate of first green rectangle. x = 50; // y coordinate of first green rectangle. y += 50; // Fill rectangles with green, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { myBrush.Color = Color.FromArgb(alpha, green); g.FillRectangle(myBrush, x, y, 50, 150); x += 50; } // x coordinate of first blue rectangle. x = 50; // y coordinate of first blue rectangle. y += 100; // Fill rectangles with blue, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { myBrush.Color = Color.FromArgb(alpha, blue); g.FillRectangle(myBrush, x, y, 50, 150); x += 50; } }
void FromArgb2( PaintEventArgs^ e ) { Graphics^ g = e->Graphics; // Opaque colors (alpha value defaults to 255 -- max value). Color red = Color::FromArgb( 255, 0, 0 ); Color green = Color::FromArgb( 0, 255, 0 ); Color blue = Color::FromArgb( 0, 0, 255 ); // Solid brush initialized to red. SolidBrush^ myBrush = gcnew SolidBrush( red ); int alpha; // x coordinate of first red rectangle int x = 50; // y coordinate of first red rectangle int y = 50; // Fill rectangles with red, varying the alpha value from 25 to 250. for ( alpha = 25; alpha <= 250; alpha += 25 ) { myBrush->Color = Color::FromArgb( alpha, red ); g->FillRectangle( myBrush, x, y, 50, 100 ); g->FillRectangle( myBrush, x, y + 250, 50, 50 ); x += 50; } x = 50; // y coordinate of first green rectangle. y += 50; // Fill rectangles with green, varying the alpha value from 25 to 250. for ( alpha = 25; alpha <= 250; alpha += 25 ) { myBrush->Color = Color::FromArgb( alpha, green ); g->FillRectangle( myBrush, x, y, 50, 150 ); x += 50; } x = 50; // y coordinate of first blue rectangle. y += 100; // Fill rectangles with blue, varying the alpha value from 25 to 250. for ( alpha = 25; alpha <= 250; alpha += 25 ) { myBrush->Color = Color::FromArgb( alpha, blue ); g->FillRectangle( myBrush, x, y, 50, 150 ); x += 50; } }
public void FromArgb2(PaintEventArgs e) { Graphics g = e.get_Graphics(); // Opaque colors (alpha value defaults to 255 -- max value). Color red = Color.FromArgb(255, 0, 0); Color green = Color.FromArgb(0, 255, 0); Color blue = Color.FromArgb(0, 0, 255); // Solid brush initialized to red. SolidBrush myBrush = new SolidBrush(red); int alpha; // x coordinate of first red rectangle int x = 50; // y coordinate of first red rectangle int y = 50; // Fill rectangles with red, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha+=25) { myBrush.set_Color(Color.FromArgb(alpha, red)); g.FillRectangle(myBrush, x, y, 50, 100); g.FillRectangle(myBrush, x, y + 250, 50, 50); x += 50; } // x coordinate of first green rectangle. x = 50; // y coordinate of first green rectangle. y+=50; // Fill rectangles with green, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha+=25) { myBrush.set_Color(Color.FromArgb(alpha, green)); g.FillRectangle(myBrush, x, y, 50, 150); x += 50; } // x coordinate of first blue rectangle. x = 50; // y coordinate of first blue rectangle. y += 100; // Fill rectangles with blue, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha+=25) { myBrush.set_Color(Color.FromArgb(alpha, blue)); g.FillRectangle(myBrush, x, y, 50, 150); x += 50; } } //FromArgb2
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, 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 version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ