GUI/Maximum window dimensions: Difference between revisions

(→‎{{header|Perl 6}}: Add a Perl 6 example)
Line 893:
 
The alternative method is to create a form that is maximized and then query its dimensions (similar to the method used in gambas).
 
=={{header|Visual Basic .NET}}==
'''Compiler:''' Roslyn Visual Basic (language version >= 14, e.g. with Visual Studio 2015)
{{works with|.NET Framework|4.7.2}} (simple enough that it should probably work on every Framework version--.NET Core 3.0 will support Windows Forms on Windows only)
Must be referenced:
{{libheader|System.Drawing.dll}}
{{libheader|System.Windows.Forms.dll}}
 
Bounds are the screen's dimensions; working area is the is the region that excludes "taskbars, docked windows, and docked tool bars" (from Framework documentation).
 
<lang vbnet>Imports System.Drawing
Imports System.Windows.Forms
 
Module Program
Sub Main()
Dim bounds As Rectangle = Screen.PrimaryScreen.Bounds
Console.WriteLine($"Primary screen bounds: {bounds.Width}x{bounds.Height}")
 
Dim workingArea As Rectangle = Screen.PrimaryScreen.WorkingArea
Console.WriteLine($"Primary screen working area: {workingArea.Width}x{workingArea.Height}")
End Sub
End Module</lang>
 
{{out}}
<pre>Primary screen bounds: 1714x1143
Primary screen working area: 1714x1103</pre>
 
Alternatively, use the dimensions of a borderless form with WindowState set to FormWindowState.Maximized (i.e. a full-screen window that is shown above the taskbar).
 
<lang vbnet>Imports System.Drawing
Imports System.Windows.Forms
 
Module Program
Sub Main()
Using f As New Form() With {
.WindowState = FormWindowState.Maximized,
.FormBorderStyle = FormBorderStyle.None
}
 
f.Show()
Console.WriteLine($"Size of maximized borderless form: {f.Width}x{f.Height}")
End Using
End Sub
End Module</lang>
 
{{out}}
<pre>Size of maximized borderless form: 1714x1143</pre>
 
[[Category:Initialization]]
Anonymous user