RichTextBox.SelectionColor Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit la couleur du texte de la sélection de texte ou du point d’insertion actuel.
public:
property System::Drawing::Color SelectionColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Color SelectionColor { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionColor : System.Drawing.Color with get, set
Public Property SelectionColor As Color
Valeur de propriété
Qui Color représente la couleur à appliquer à la sélection de texte actuelle ou au texte entré après le point d’insertion.
- Attributs
Exemples
L’exemple de code suivant affiche un ColorDialog utilisateur pour spécifier une couleur pour la sélection de texte actuelle ou le texte entré après le point d’insertion actuel dans un RichTextBox contrôle. Cet exemple nécessite que la méthode définie dans l’exemple soit ajoutée à une Form classe qui contient un RichTextBox contrôle nommé richTextBox1.
public:
void ChangeMySelectionColor()
{
ColorDialog^ colorDialog1 = gcnew ColorDialog;
// Set the initial color of the dialog to the current text color.
colorDialog1->Color = richTextBox1->SelectionColor;
// Determine if the user clicked OK in the dialog and that the color has changed.
if ( colorDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
colorDialog1->Color != richTextBox1->SelectionColor )
{
// Change the selection color to the user specified color.
richTextBox1->SelectionColor = colorDialog1->Color;
}
}
public void ChangeMySelectionColor()
{
ColorDialog colorDialog1 = new ColorDialog();
// Set the initial color of the dialog to the current text color.
colorDialog1.Color = richTextBox1.SelectionColor;
// Determine if the user clicked OK in the dialog and that the color has changed.
if(colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
colorDialog1.Color != richTextBox1.SelectionColor)
{
// Change the selection color to the user specified color.
richTextBox1.SelectionColor = colorDialog1.Color;
}
}
Public Sub ChangeMySelectionColor()
Dim colorDialog1 As New ColorDialog()
' Set the initial color of the dialog to the current text color.
colorDialog1.Color = richTextBox1.SelectionColor
' Determine if the user clicked OK in the dialog and that the color has
' changed.
If (colorDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
And Not(colorDialog1.Color.Equals(richTextBox1.SelectionColor)) Then
' Change the selection color to the user specified color.
richTextBox1.SelectionColor = colorDialog1.Color
End If
End Sub
Remarques
Si la sélection de texte actuelle a plusieurs couleurs spécifiées, cette propriété retourne Color.Empty. Si aucun texte n’est actuellement sélectionné, la couleur de texte spécifiée dans cette propriété est appliquée au point d’insertion actuel et à tout le texte tapé dans le contrôle après le point d’insertion. Le paramètre de couleur de texte s’applique jusqu’à ce que la propriété soit remplacée par une couleur différente ou jusqu’à ce que le point d’insertion soit déplacé vers une autre section du contrôle.
Si le texte est sélectionné dans le contrôle, le texte sélectionné et tout texte entré après la sélection de texte aura la valeur de cette propriété. Vous pouvez utiliser cette propriété pour modifier la couleur du texte dans le RichTextBox.
Pour mettre du texte en gras dans le contrôle, utilisez la SelectionFont propriété pour affecter une nouvelle police dont le style de police gras est spécifié.