Freigeben über


FontDialog.Color-Eigenschaft

Ruft die ausgewählte Schriftfarbe ab oder legt diese fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Property Color As Color
'Usage
Dim instance As FontDialog
Dim value As Color

value = instance.Color

instance.Color = value
public Color Color { get; set; }
public:
property Color Color {
    Color get ();
    void set (Color value);
}
/** @property */
public Color get_Color ()

/** @property */
public void set_Color (Color value)
public function get Color () : Color

public function set Color (value : Color)

Eigenschaftenwert

Die Farbe der ausgewählten Schriftart. Der Standardwert ist Black.

Beispiel

Im folgenden Codebeispiel wird ShowDialog zum Anzeigen eines FontDialog verwendet. Voraussetzung für diesen Code ist, dass Form bereits mit TextBox erstellt wurde und Schaltflächen darauf platziert sind. Weiterhin wird davon ausgegangen, dass fontDialog1 erstellt wurde. Font enthält die Größeninformationen, jedoch nicht die Farbinformationen.

Private Sub button1_Click(sender As Object, e As System.EventArgs)
    fontDialog1.ShowColor = True

    fontDialog1.Font = textBox1.Font
    fontDialog1.Color = textBox1.ForeColor

    If fontDialog1.ShowDialog() <> DialogResult.Cancel Then
        textBox1.Font = fontDialog1.Font
        textBox1.ForeColor = fontDialog1.Color
    End If
End Sub 'button1_Click
private void button1_Click(object sender, System.EventArgs e)
 {
    fontDialog1.ShowColor = true;

    fontDialog1.Font = textBox1.Font;
    fontDialog1.Color = textBox1.ForeColor;

    if(fontDialog1.ShowDialog() != DialogResult.Cancel )
    {
       textBox1.Font = fontDialog1.Font ;
       textBox1.ForeColor = fontDialog1.Color;
    }
 }
 
private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      fontDialog1->ShowColor = true;

      fontDialog1->Font = textBox1->Font;
      fontDialog1->Color = textBox1->ForeColor;

      if ( fontDialog1->ShowDialog() != ::DialogResult::Cancel )
      {
         textBox1->Font = fontDialog1->Font;
         textBox1->ForeColor = fontDialog1->Color;
      }
   }
protected void button1_Click(Object sender, System.EventArgs e)
{
    fontDialog1.set_ShowColor(true);
    fontDialog1.set_Font(textBox1.get_Font());
    fontDialog1.set_Color(textBox1.get_ForeColor());
    if (!(fontDialog1.ShowDialog().Equals(get_DialogResult().Cancel))) {
        textBox1.set_Font(fontDialog1.get_Font());
        textBox1.set_ForeColor(fontDialog1.get_Color());
    }
} //button1_Click

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

FontDialog-Klasse
FontDialog-Member
System.Windows.Forms-Namespace
Color
Font
ShowColor