# Application Switches

<mark style="color:green;background-color:green;">Since 3.5.6</mark>

Some default behaviors in Wisej.NET are configurable with [`AppContext`](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-appcontext) switches. These are the switches currently supported:

## Label Self Size

**`LabelSelfSize`** (default: `true`)

The behavior of `AutoSize` in `Label` controls differs from other controls, especially in standard containers like `Panel`, `Form`, `Page`, or `GroupBox`. When a `Label` is right-anchored in these containers, `AutoSize` adjusts width while maintaining the left position. This ensures the `Label` expands/contracts rightward without moving its left edge.

When the `Label` is in a custom layout container (`FlexLayoutPanel`, `FlowLayoutPanel`, `TableLayoutPanel`), `AutoSize` behaves like other controls.

Corresponds to `Label.SelfSizeDefault` and `Label.SelfSize`.

## DataGridView Auto Select

**`DataGridViewAutoSelectFirstRow`** (default: `true`)

By default, setting the current cell in a `DataGridView` selects the row, cell, or column based on `SelectionMode`. To prevent automatic selection when setting the current cell, set `DataGridViewAutoSelectFirstRow` to `false`.

Corresponds to `DataGridView.AutoSelectFirstRowDefault` and `DataGridView.AutoSelectFirstRow`.

## DataGridView Auto Generate

**`DataGridViewAutoGenerateColumns`** (default: `true`)

The `DataGridView` automatically generates columns when `DataSource` is assigned in the designer, then sets `AutoGenerateColumns` to `false` after creating and serializing columns. Setting `DataSource` to null resets `AutoGenerateColumns` to `true`.

You cannot set `AutoGenerateColumns` in the designer as it's managed with the `DataSource` property. However, you can set its default initial value to `false` using the `DataGridViewAutoGenerateColumns` switch.

Corresponds to `DataGridView.AutoGenerateColumnsDefault`.

## Form Auto Close

**`FormAutoCloseModalDialog`** (default: `false`)

In Wisej.NET, modal dialogs require calling `Close()` to close. Setting `AutoCloseModalDialog` to `true` enables automatic closure when `Form.DialogResult` is set to any value except `DialogResult.None`.

When `AutoCloseModalDialog` is `true`, the dialog closes automatically when:

* User clicks `AcceptButton` or `CancelButton` with `DialogResult` set
* Code sets the `DialogResult` property

This matches WinForms behavior but differs from Wisej.NET's default.

Corresponds to `Form.AutoCloseModalDialogDefault` and `Form.AutoCloseModalDialog`.

## Setting AppContext Switches

See Microsoft's [`System.AppContext`](https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-appcontext) documentation for various configuration approaches. Example code setup:

{% tabs %}
{% tab title="C#" %}

```csharp
// Program static contstructor
public static class Program {
    
    public void static Program() {
        AppContext.SetSwitch("LabelSelfSize", false);
    }
}
```

{% endtab %}

{% tab title="VB.NET" %}

```vbnet
'' Program static constructor
Module Program
    
    Sub New()
        AppContext.SetSwitch("LabelSelfSize", False)
    End Sub

End Module
```

{% endtab %}
{% endtabs %}


---

# 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://docs.wisej.com/docs/concepts/application-switches.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.
