Check the screen size

blumonde

Well-known member
Joined
Jul 26, 2005
Messages
68
Programming Experience
Beginner
Hi Folks,

Is there a way to check the size of the screen so that my form will load to fit the current screen size?

I have different users with small or large screens. Some of them with small screens are unable to view the whole form.

Please show me how to do it.

Thanks.

Cheers, :)

blumonde
 
i plan all programs to be able to be viewed at 800x600 (i do put a minimum screen size warning too)

of which i'm also a fan of multiple forms (to maintain the 800x600 rule)

but i'm also sure there's a way to check the current screen size and have the program modify itself accordingly too
 
JuggaloBrotha said:
i plan all programs to be able to be viewed at 800x600 (i do put a minimum screen size warning too)

of which i'm also a fan of multiple forms (to maintain the 800x600 rule)

but i'm also sure there's a way to check the current screen size and have the program modify itself accordingly too

Hi there JuggaloBrotha,

I think there is a way but I surely don't know how to get to it. Maybe Kulrom or Jmn know. I give up.

Cheers :)

blumonde
 
after doing a quick google search

this module will allow you to change the resolution:
VB.NET:
Module Resolution
	Public Class ChangeResolution
		Const CCDEVICENAME As Short = 32
		Const CCFORMNAME As Short = 32
		Const DM_BITSPERPEL As Integer = &H40000
		Const DM_PELSWIDTH As Integer = &H80000
		Const DM_PELSHEIGHT As Integer = &H100000
		Const CDS_UPDATEREGISTRY As Short = &H1S
		Const CDS_TEST As Short = &H4S
		Const DISP_CHANGE_SUCCESSFUL As Short = 0
		Const DISP_CHANGE_RESTART As Short = 1
		Const BITSPIXEL As Short = 12

		Private Structure DEVMODE
		    <VBFixedString(CCDEVICENAME), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> Public dmDeviceName As String
			Dim dmSpecVersion As Short
			Dim dmDriverVersion As Short
			Dim dmSize As Short
			Dim dmDriverExtra As Short
			Dim dmFields As Integer
			Dim dmOrientation As Short
			Dim dmPaperSize As Short
			Dim dmPaperLength As Short
			Dim dmPaperWidth As Short
			Dim dmScale As Short
			Dim dmCopies As Short
			Dim dmDefaultSource As Short
			Dim dmPrintQuality As Short
			Dim dmColor As Short
			Dim dmDuplex As Short
			Dim dmYResolution As Short
			Dim dmTTOption As Short
			Dim dmCollate As Short
		    <VBFixedString(CCFORMNAME), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=CCFORMNAME)> Public dmFormName As String
			Dim dmUnusedPadding As Short
			Dim dmBitsPerPel As Short
			Dim dmPelsWidth As Integer
			Dim dmPelsHeight As Integer
			Dim dmDisplayFlags As Integer
			Dim dmDisplayFrequency As Integer
		End Structure

		Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Integer, ByVal iModeNum As Integer, ByRef lpDevMode As DEVMODE) As Boolean
		Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (ByRef lpDevMode As DEVMODE, ByVal dwFlags As Integer) As Integer

		Public Shared Sub ChangeRes(ByRef X As Integer, ByRef Y As Integer, ByRef Bits As Integer, ByRef Freq As Integer)
			Dim DevM As DEVMODE
			Dim ScInfo, erg As Integer
			Dim an As MsgBoxResult
			'Get the info into DevM 
			erg = EnumDisplaySettings(0, 0, DevM)
			'This is what we're going to change 
		    DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
			DevM.dmPelsWidth = X 'ScreenWidth 
			DevM.dmPelsHeight = Y 'ScreenHeight 
			DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4) 
			DevM.dmDisplayFrequency = Freq '(can be 60, 70, 72, 75 or 85)
			'Now change the display and check if possible 
			erg = ChangeDisplaySettings(DevM, CDS_TEST)
		End Sub
	End Class
End Module
 
The Screen class will give you all the information you want about resolution and so forth, which would allow you to resize your form. If you actually want to change the system resolution then I think you would have to use something like JB's code.
 
Thank you all getlemen for your help.

I would like to be able to resize the screen form programatically upon entry. Not changing the resolution.

I couldn't find any example in msdn to show me how to do so.


blumonde
 
You don't need an MSDN example, just a bit of investigation and deduction. I suggested using the Screen class. A quick browse through the members of the Screen class would bring you to the PrimaryScreen property, which I'd say is self-explanatory, and the Bounds property, which is a Rectangle describing the bounds of the Screen object. Thus you would get the resolution of the main monitor from the Width and Height properties of the Screen.PrimaryScreen.Bounds property. You would then set the size of your form accordingly. Obviously this must be done at run time, with the logical place being the Load event handler.
 
jmcilhinney said:
You don't need an MSDN example, just a bit of investigation and deduction. I suggested using the Screen class. A quick browse through the members of the Screen class would bring you to the PrimaryScreen property, which I'd say is self-explanatory, and the Bounds property, which is a Rectangle describing the bounds of the Screen object. Thus you would get the resolution of the main monitor from the Width and Height properties of the Screen.PrimaryScreen.Bounds property. You would then set the size of your form accordingly. Obviously this must be done at run time, with the logical place being the Load event handler.

Thanks jmc. So far, I was able to get it partially working. However, I still have to hardcode the rightbound of the screen. I tried different things but unable to figure out how to obtain the right bound of the screen width. Below is my code:

Dim workingRectangle As System.Drawing.Rectangle = _

Screen.PrimaryScreen.WorkingArea

' Set the size of the form slightly less than size of

' working rectangle.

Me.Size = New System.Drawing.Size(workingRectangle.Width - 500, _

workingRectangle.Height - 194)

' Set the location so the entire form is visible.

Me.Location = New System.Drawing.Point(5, 5)

Me.Location = New Point(500, 150)

'*********************************

The statement
Me.Size = New System.Drawing.Size(workingRectangle.Width - 500, workingRectangle.Height - 194)

is where I am having a problem with. I don't want to hardcode 500 as the right boundary. I need to get that number by calculation because each user screen has a different width boundary. My screen works okay with 500 but not other screens.

Cheers :)

blumonde


 
here is an easy way:


Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width

Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height

Me.Height = intY

Me.Width = intX

Me.Top = 0

Me.Left = 0

MsgBox(intX &
" X " & intY)

 
cablehead said:
here is an easy way:


Dim intX AsInteger = Screen.PrimaryScreen.Bounds.Width

Dim intY AsInteger = Screen.PrimaryScreen.Bounds.Height

Me.Height = intY

Me.Width = intX

Me.Top = 0

Me.Left = 0

MsgBox(intX &
" X " & intY)


Hi Cable,

I got it done already. Thanks.

Cheers,

blumonde
 
Back
Top