# Kleuren in Console

{% hint style="success" %}
[Kennisclip voor deze inhoud](https://youtu.be/VhM-zg7Rt_U)
{% endhint %}

## Kleuren in console

Je kan in console-applicaties zelf bepalen in welke kleur nieuwe tekst op het scherm verschijnt. Je kan zowel de kleur van het lettertype instellen (via `ForegroundColor`) als de achtergrondkleur (`BackgroundColor`).

Je kan met de volgende expressies de console-kleur veranderen, bijvoorbeeld de achtergrond in blauw en de letters in groen:

```csharp
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Green;
```

Vanaf dan zal alle tekst die je na deze 2 expressies via `WriteLine` naar het scherm stuurt met deze kleuren werken.

Een voorbeeld:

```csharp
Console.WriteLine("Tekst in de standaard kleur");
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Deze tekst komt in het groen met blauwe achtergrond");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("En deze in het rood met blauwe achtergrond");
```

Als je deze code uitvoert krijg je als resultaat:

![Resultaat voorgaande code](https://4286502012-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LiTpB3KNqWfMzRf0oYc%2F-M22Nb3xxvjlraRlZV9u%2F-M22Nfp_fwk1xOPsK_bD%2Fkleuren.PNG?generation=1583826010635408\&alt=media)

{% hint style="info" %}
Kleur in console gebruiken is nuttig om je gebruikers een minder eentonig en meer informatieve applicatie aan te bieden. Je zou bijvoorbeeld alle foutmeldingen in het rood kunnen laten verschijnen.
{% endhint %}

## Kleur resetten

Soms wil je terug de originele applicatie-kleuren hebben. Je zou manueel dit kunnen instellen, maar wat als de gebruiker slecht ziend is en in z'n besturingssysteem andere kleuren als standaard heeft ingesteld?!

De veiligste manier is daarom de kleuren te resetten door de `Console.ResetColor()` methode aan te roepen zoals volgend voorbeeld toont:

```csharp
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error!!!! Contacteer de helpdesk");
Console.ResetColor();
Console.WriteLine("Het programma sluit nu af");
```

## Mogelijke kleuren

Alle kleuren die beschikbaar zijn zijn beschreven in `ConsoleColor` deze zijn:

* `ConsoleColor.Black`
* `ConsoleColor.DarkBlue`
* `ConsoleColor.DarkGreen`
* `ConsoleColor.DarkCyan`
* `ConsoleColor.DarkRed`
* `ConsoleColor.DarkMagenta`
* `ConsoleColor.DarkYellow`
* `ConsoleColor.Gray`
* `ConsoleColor.DarkGray`
* `ConsoleColor.Blue`
* `ConsoleColor.Green`
* `ConsoleColor.Cyan`
* `ConsoleColor.Red`
* `ConsoleColor.Magenta`
* `ConsoleColor.Yellow`

![Bron afbeelding : https://www.c-sharpcorner.com/article/change-console-foreground-and-background-color-in-c-sharp/](https://4286502012-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LiTpB3KNqWfMzRf0oYc%2Fsync%2F46c1960f7b3ccd678a7ccc2ad94ab6c7b296cdca.jpg?generation=1588682478713894\&alt=media)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apwt.gitbook.io/cursus-pro-oo/semester-1-programming-principles/h0-werken-met-visual-studio/5_kleuren.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
