https://github.com/tatsuyafujisaki/winforms-cheat-sheet
https://github.com/tatsuyafujisaki/winforms-cheat-sheet
cheat-sheet csharp winforms
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tatsuyafujisaki/winforms-cheat-sheet
- Owner: tatsuyafujisaki
- Created: 2016-06-29T15:45:51.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2021-01-07T13:30:25.000Z (over 5 years ago)
- Last Synced: 2025-03-24T00:55:36.386Z (about 1 year ago)
- Topics: cheat-sheet, csharp, winforms
- Language: C#
- Homepage:
- Size: 20.5 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://ci.appveyor.com/project/tatsuya/winforms-cheat-sheet)
# Best practices
## Form
* `AutoSize` = `True`
* `AutoSizeMode` = `GrowAndShrink`
* `StartPosition` = `CenterScreen`
* `Form.CenterToScreen()` is not intended to be used directly from your code.
* https://msdn.microsoft.com/en-us/library/system.windows.forms.form.centertoscreen.aspx
* `TopMost` = `True`
## ComboBox
* `Sorted` = `True`
## DataGridView
* `MultiSelect` = `False`
## ListView
```csharp
liewView1.BeginUpdate();
liewView1.Items.Clear();
// Say, xs is defined somewhere else.
foreach (var lvi in xs.Select(x => new ListViewItem(new[]
{
x.Foo,
x.Bar,
x.Baz
}) { Tag = x }))
{
liewView1.Items.Add(lvi);
}
liewView1.AutoResizeColumns(liewView1.Items.Count == 0
? ColumnHeaderAutoResizeStyle.HeaderSize
: ColumnHeaderAutoResizeStyle.ColumnContent);
liewView1.EndUpdate();
```