UI

Introduction

To use these methods and features, do not forget to put this line of code in your "using" region:

C#

using LeoCorpLibrary.UI;

VB

Imports LeoCorpLibrary.UI

WinFormsHelpers

a. CenterControlOnForm

This function is available in version 2.3 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.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) {...}
ValueArgumentDescription
ControlcontrolThe control to center
FormformThe form where the control is going to be center

Variation 2

WinFormsHelpers.CenterControlOnForm(Control control, Form form, ControlAlignment controlAlignment) {...}
ValueArgumentDescription
ControlcontrolThe control to center
FormformThe form where the control is going to be center
ControlAlignmentcontrolAlignmentThe alignment 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, VerticalAlignment.Vertical); // Center the label vertically

VB

' 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, VerticalAlignment.Vertical) ' Center the label vertically

Go to top

b. CenterFormOnScreen

This function is available in version 2.3 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.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:

ValueArgumentDescription
FormformThe Form to center inside a Screen

Here's an example of usage:

C#

WinFormsHelpers.CenterFormOnScreen(this); // Center the form

VB

WinFormsHelpers.CenterFormOnScreen(Me) ' Center the form

Go to top

ScreenHelpers

a. GetScreenDPIFromWinForm

This function is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.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:

ValueArgumentDescription
FormformThe Form to get the DPI of

Here's an example of usage:

C#

ScreenHelpers.GetScreenDPIFromWinForm(this); // Get the screen DPI

VB

ScreenHelpers.GetScreenDPIFromWinForm(Me) ' Get the screen DPI

Go to top

b. GetScreenDPIFromWPFWindow

This function is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.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:

ValueArgumentDescription
WindowwindowThe window to get the DPI of

Here's an example of usage:

C#

ScreenHelpers.GetScreenDPIFromWPFWindow(this); // Get the screen DPI

VB

ScreenHelpers.GetScreenDPIFromWPFWindow(Me) ' Get the screen DPI

Go to top

c. GetScreenScalingFromWinForm

This function is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.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:

ValueArgumentDescription
FormformThe form to get the scale of

Here's an example of usage:

C#

ScreenHelpers.GetScreenScalingFromWinForm(this); // Get the screen scale

VB

ScreenHelpers.GetScreenScalingFromWinForm(Me) ' Get the screen scale

Go to top

d. GetScreenScalingFromWPFWindow

This function is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.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:

ValueArgumentDescription
WindowwindowThe window to get the scale of

Here's an example of usage:

C#

ScreenHelpers.GetScreenScalingFromWPFWindow(this); // Get the screen scale

VB

ScreenHelpers.GetScreenScalingFromWPFWindow(Me) ' Get the screen scale

Go to top

ControlAlignment

ControlAlignment is an enumeration which has three elements:

  • Horizontal
  • Vertical
  • Both

This enumeration can be used in the CenterControlOnForm() method.

Go to top