ColorDialog, classe
Assembly : System.Windows.Forms (dans system.windows.forms.dll)
Le membre hérité ShowDialog doit être appelé pour créer cette boîte de dialogue commune spécifique. HookProc peut être substitué pour implémenter une fonctionnalité de raccordement d'une boîte de dialogue spécifique. Utilisez Color pour récupérer la couleur sélectionnée par l'utilisateur.
Lorsque vous créez une instance de ColorDialog, les valeurs initiales sont affectées à certaines propriétés de lecture/écriture. Pour obtenir la liste de ces valeurs, consultez le constructeur ColorDialog.
L'exemple suivant illustre la création d'un nouveau ColorDialog. Cet exemple requiert que la méthode soit appelée à partir d'un formulaire existant, doté de TextBox et de Button.
private void button1_Click(object sender, System.EventArgs e) { ColorDialog MyDialog = new ColorDialog(); // Keeps the user from selecting a custom color. MyDialog.AllowFullOpen = false ; // Allows the user to get help. (The default is false.) MyDialog.ShowHelp = true ; // Sets the initial color select to the current text color. MyDialog.Color = textBox1.ForeColor ; // Update the text box color if the user clicks OK if (MyDialog.ShowDialog() == DialogResult.OK) textBox1.ForeColor = MyDialog.Color; }
protected void button1_Click(Object sender, System.EventArgs e)
{
ColorDialog myDialog = new ColorDialog();
// Keeps the user from selecting a custom color.
myDialog.set_AllowFullOpen(false);
// Allows the user to get help. (The default is false.)
myDialog.set_ShowHelp(true);
// Sets the initial color select to the current text color.
myDialog.set_Color(textBox1.get_ForeColor());
// Update the text box color if the user clicks OK
if (myDialog.ShowDialog().Equals(get_DialogResult().OK)) {
textBox1.set_ForeColor(myDialog.get_Color());
}
} //button1_Click
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.CommonDialog
System.Windows.Forms.ColorDialog
Windows 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.