User Interface - Leo-Corporation/LeoCorpLibrary GitHub Wiki
To use these methods and features, do not forget to put this line of code on top of your code file:
C#
using LeoCorpLibrary.UI;VB
Imports LeoCorpLibrary.UIThis function is available in version 2.3 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | â | â |
| .NET Core 3.1 | â | â |
| .NET Framework 4.7.2 | â | â |
| .NET Framework 4.5 | â | â |
The CenterControlOnForm() method allows you to center a Control inside a Form.
It's in:
LeoCorpLibrary.UI.WinFormsHelpers.CenterControlOnForm()It has two variations:
Variation 1
WinFormsHelpers.CenterControlOnForm(Control control, Form form) {...}| Value | Argument | Description |
|---|---|---|
| Control | control | The control to center |
| Form | form | The form where the control is going to be center |
Variation 2
WinFormsHelpers.CenterControlOnForm(Control control, Form form, ControlAlignement controlAlignement) {...}| Value | Argument | Description |
|---|---|---|
| Control | control | The control to center |
| Form | form | The form where the control is going to be center |
| ControlAlignement | controlAlignement | The alignement of the control (Vertical, Horizontal or Both) |
Here's an example of usage:
C#
// Variation 1
Label label = new Label();
label.Text = "Hi!";
WinFormsHelpers.CenterControlOnForm(label, this); // "this" is the current object, here, it's a Form
// Variation 2
WinFormsHelpers.CenterControlOnForm(label, this, VerticalAlignement.Vertical); // Center the label verticallyVB
' Variation 1
Dim label As Label = New Label()
label.Text = "Hi!"
WinFormsHelpers.CenterControlOnForm(label, Me) ' "Me" is the current object, here, it's a Form
' Variation 2
WinFormsHelpers.CenterControlOnForm(label, this, VerticalAlignement.Vertical) ' Center the label verticallyThis function is available in version 2.3 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | â | â |
| .NET Core 3.1 | â | â |
| .NET Framework 4.7.2 | â | â |
| .NET Framework 4.5 | â | â |
The CenterFormOnScreen() method allows you to center a Form inside the primary Screen.
It's in:
LeoCorpLibrary.UI.WinFormsHelpers.CenterFormOnScreen()It has one argument:
| Value | Argument | Description |
|---|---|---|
| Form | form | The Form to center inside a Screen |
Here's an example of usage:
C#
WinFormsHelpers.CenterFormOnScreen(this); // Center the formVB
WinFormsHelpers.CenterFormOnScreen(Me) ' Center the formThis function is available in version 3.7 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | â | â |
| .NET Core 3.1 | â | â |
| .NET Framework 4.7.2 | â | â |
| .NET Framework 4.5 | â | â |
The GetScreenDPIFromWinForm() method allows you to get the current screen DPI from a System.Windows.Forms.Form. It returns a double value.
It's in:
LeoCorpLibrary.UI.ScreenHelpers.GetScreenDPIFromWinForm()It has one argument:
| Value | Argument | Description |
|---|---|---|
| Form | form | The Form to get the DPI of |
Here's an example of usage:
C#
ScreenHelpers.GetScreenDPIFromWinForm(this); // Get the screen DPIVB
ScreenHelpers.GetScreenDPIFromWinForm(Me) ' Get the screen DPIThis function is available in version 3.7 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | â | â |
| .NET Core 3.1 | â | â |
| .NET Framework 4.7.2 | â | â |
| .NET Framework 4.5 | â | â |
The GetScreenDPIFromWPFWindow() method allows you to get the current screen DPI from a System.Windows.Window. It returns a double value.
It's in:
LeoCorpLibrary.UI.ScreenHelpers.GetScreenDPIFromWPFWindow()It has one argument:
| Value | Argument | Description |
|---|---|---|
| Window | window | The window to get the DPI of |
Here's an example of usage:
C#
ScreenHelpers.GetScreenDPIFromWPFWindow(this); // Get the screen DPIVB
ScreenHelpers.GetScreenDPIFromWPFWindow(Me) ' Get the screen DPIThis function is available in version 3.7 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | â | â |
| .NET Core 3.1 | â | â |
| .NET Framework 4.7.2 | â | â |
| .NET Framework 4.5 | â | â |
The GetScreenScalingFromWinForm() method allows you to get the current screen scale from a System.Windows.Forms.Form. It returns a double value.
It's in:
LeoCorpLibrary.UI.ScreenHelpers.GetScreenScalingFromWinForm()It has one argument:
| Value | Argument | Description |
|---|---|---|
| Form | form | The form to get the scale of |
Here's an example of usage:
C#
ScreenHelpers.GetScreenScalingFromWinForm(this); // Get the screen scaleVB
ScreenHelpers.GetScreenScalingFromWinForm(Me) ' Get the screen scaleThis function is available in version 3.7 and higher.
Compatibility
| Framework | LeoCorpLibrary | LeoCorpLibrary.Core |
|---|---|---|
| .NET 5 | â | â |
| .NET Core 3.1 | â | â |
| .NET Framework 4.7.2 | â | â |
| .NET Framework 4.5 | â | â |
The GetScreenScalingFromWPFWindow() method allows you to get the current screen scale from a System.Windows.Window. It returns a double value.
It's in:
LeoCorpLibrary.UI.ScreenHelpers.GetScreenScalingFromWPFWindow()It has one argument:
| Value | Argument | Description |
|---|---|---|
| Window | window | The window to get the scale of |
Here's an example of usage:
C#
ScreenHelpers.GetScreenScalingFromWPFWindow(this); // Get the screen scaleVB
ScreenHelpers.GetScreenScalingFromWPFWindow(Me) ' Get the screen scaleControlAlignement is an enumeration which has three elements:
- Horizontal
- Vertical
- Both
This enumeration can be used in the CenterControlOnForm() method.