RichTextBox.SelectionColor Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u de tekstkleur van de huidige tekstselectie of invoegpositie op of stelt u deze in.
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
Waarde van eigenschap
Een Color die de kleur aangeeft die moet worden toegepast op de huidige tekstselectie of op tekst die na de invoegpositie is ingevoerd.
- Kenmerken
Voorbeelden
In het volgende codevoorbeeld wordt een ColorDialog aan de gebruiker weergegeven om een kleur op te geven voor de huidige tekstselectie of tekst die is ingevoerd na de huidige invoegpositie in een RichTextBox besturingselement. Voor dit voorbeeld moet de methode die in het voorbeeld is gedefinieerd, worden toegevoegd aan een Form klasse die een besturingselement met de RichTextBox naam richTextBox1bevat.
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
Opmerkingen
Als de huidige tekstselectie meer dan één kleur heeft opgegeven, wordt deze eigenschap geretourneerd Color.Empty. Als er momenteel geen tekst is geselecteerd, wordt de tekstkleur die in deze eigenschap is opgegeven, toegepast op de huidige invoegpositie en op alle tekst die na de invoegpositie in het besturingselement is getypt. De tekstkleurinstelling is van toepassing totdat de eigenschap wordt gewijzigd in een andere kleur of totdat de invoegpositie wordt verplaatst naar een andere sectie in het besturingselement.
Als tekst in het besturingselement is geselecteerd, worden de geselecteerde tekst en alle tekst die na de tekstselectie is ingevoerd, de waarde van deze eigenschap toegepast. U kunt deze eigenschap gebruiken om de kleur van tekst in de RichTextBox.
Als u tekst vet wilt maken in het besturingselement, gebruikt u de SelectionFont eigenschap om een nieuw lettertype toe te wijzen waaraan de opgegeven tekenstijl vet is opgegeven.