Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Form Size
 

Form Size

Hi friends my windows application look nice in 1024*768 resolurion my customer computer resolution is 800*600 so he can't see the full application window he can see only half of application window so my question is can i make my application competible for all resolution if can how can i meke that. please help me.

sivakl_2001  Tuesday, September 30, 2008 2:13 AM

Hi

You can change Screen resolution as per your application.

so you can change Window Resolution when your application starts.At time of Exit you can set old Resolution.

Here is Code, i found it on net.

Code Block
Imports System.Runtime.InteropServices

' see msdn on "Changing Screen Orientation Programmatically" for tablet pc.
' note: I couldn't change orientation on xp, or find anyone claiming they could!
' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tbconChgScrn.asp


<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Friend Structure DEVMODE

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Public dmDeviceName As String
Public dmSpecVersion As Short
Public dmDriverVersion As Short
Public dmSize As Short
Public dmDriverExtra As Short
Public dmFields As Integer
Public dmPositionX As Integer
Public dmPositionY As Integer
Public dmDisplayOrientation As Integer
Public dmDisplayFixedOutput As Integer
Public dmColor As Short
Public dmDuplex As Short
Public dmYResolution As Short
Public dmTTOption As Short
Public dmCollate As Short
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Public dmFormName As String
Public dmLogPixels As Short
Public dmBitsPerPel As Short
Public dmPelsWidth As Integer
Public dmPelsHeight As Integer
Public dmDisplayFlags As Integer
Public dmDisplayFrequency As Integer
Public dmICMMethod As Integer
Public dmICMIntent As Integer
Public dmMediaType As Integer
Public dmDitherType As Integer
Public dmReserved1 As Integer
Public dmReserved2 As Integer
Public dmPanningWidth As Integer
Public dmPanningHeight As Integer
End
Structure

Friend
Class NativeMethods

' PInvoke declaration for EnumDisplaySettings Win32 API
<DllImport("user32.dll", CharSet:=CharSet.Ansi)> _
Public Shared Function EnumDisplaySettings( _
ByVal lpszDeviceName As String, _
ByVal iModeNum As Integer, _
ByRef lpDevMode As DEVMODE) As Integer
End Function

' PInvoke declaration for ChangeDisplaySettings Win32 API
<DllImport("user32.dll", CharSet:=CharSet.Ansi)> _
Public Shared Function ChangeDisplaySettings( _
ByRef lpDevMode As DEVMODE, _
ByVal dwFlags As Integer) As Integer
End Function

End
Class

Public
Class ResolutionChanger

Private Shared Function CreateDevMode() As DEVMODE
Dim dm As New DEVMODE
dm.dmDeviceName =
New String(New Char(32) {})
dm.dmFormName =
New String(New Char(32) {})
dm.dmSize =
CShort(Marshal.SizeOf(dm))
Return dm
End Function

Public Enum DisplayChangeResultCode
DISP_CHANGE_SUCCESSFUL = 0
DISP_CHANGE_RESTART = 1
DISP_CHANGE_FAILED = -1
DISP_CHANGE_BADMODE = -2
DISP_CHANGE_NOTUPDATED = -3
DISP_CHANGE_BADFLAGS = -4
DISP_CHANGE_BADPARAM = -5
DISP_CHANGE_BADDUALVIEW = -6
End Enum

Public Shared Sub ChangeResolution(ByVal width As Integer, ByVal height As Integer, ByVal freq As Integer)

Const DM_PELSWIDTH As Integer = &H80000
Const DM_PELSHEIGHT As Integer = &H100000
Const DM_DISPLAYFREQUENCY As Integer = &H400000
Const ENUM_CURRENT_SETTINGS As Integer = -1
Dim DevM As DEVMODE = CreateDevMode()
Dim enumResult As Integer
Dim changeResult As DisplayChangeResultCode

DevM.dmFields = DM_PELSWIDTH
Or DM_PELSHEIGHT Or DM_DISPLAYFREQUENCY

enumResult = NativeMethods.EnumDisplaySettings(
Nothing, ENUM_CURRENT_SETTINGS, DevM)

DevM.dmPelsWidth = width
DevM.dmPelsHeight = height
DevM.dmDisplayFrequency = freq

changeResult =
CType(NativeMethods.ChangeDisplaySettings(DevM, 0), DisplayChangeResultCode)

If changeResult <> DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL Then
Throw New Exception("Failed to change resolution: " & changeResult.ToString)
End If

End Sub

End
Class

I am using this code. and it works fine.

if you got any error, let me know.

Thank You.

Best Regards

Utkarsh Gajjar

Utkarsh  Tuesday, September 30, 2008 2:22 PM

Hi sivakl_2001

You can set the Size property of your form base on the screen resolution. Here is an FAQ. Please look at this for reference.

http://www.syncfusion.com/faq/windowsforms/search/1002.aspx

In this FAQ, you can use Screen.PrimarScreen.Bounds to get the screen resolution.

Sincerely,

Kira Qian

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Kira Qian  Thursday, October 02, 2008 4:02 AM

Hi

You can change Screen resolution as per your application.

so you can change Window Resolution when your application starts.At time of Exit you can set old Resolution.

Here is Code, i found it on net.

Code Block
Imports System.Runtime.InteropServices

' see msdn on "Changing Screen Orientation Programmatically" for tablet pc.
' note: I couldn't change orientation on xp, or find anyone claiming they could!
' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tbconChgScrn.asp


<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Friend Structure DEVMODE

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Public dmDeviceName As String
Public dmSpecVersion As Short
Public dmDriverVersion As Short
Public dmSize As Short
Public dmDriverExtra As Short
Public dmFields As Integer
Public dmPositionX As Integer
Public dmPositionY As Integer
Public dmDisplayOrientation As Integer
Public dmDisplayFixedOutput As Integer
Public dmColor As Short
Public dmDuplex As Short
Public dmYResolution As Short
Public dmTTOption As Short
Public dmCollate As Short
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Public dmFormName As String
Public dmLogPixels As Short
Public dmBitsPerPel As Short
Public dmPelsWidth As Integer
Public dmPelsHeight As Integer
Public dmDisplayFlags As Integer
Public dmDisplayFrequency As Integer
Public dmICMMethod As Integer
Public dmICMIntent As Integer
Public dmMediaType As Integer
Public dmDitherType As Integer
Public dmReserved1 As Integer
Public dmReserved2 As Integer
Public dmPanningWidth As Integer
Public dmPanningHeight As Integer
End
Structure

Friend
Class NativeMethods

' PInvoke declaration for EnumDisplaySettings Win32 API
<DllImport("user32.dll", CharSet:=CharSet.Ansi)> _
Public Shared Function EnumDisplaySettings( _
ByVal lpszDeviceName As String, _
ByVal iModeNum As Integer, _
ByRef lpDevMode As DEVMODE) As Integer
End Function

' PInvoke declaration for ChangeDisplaySettings Win32 API
<DllImport("user32.dll", CharSet:=CharSet.Ansi)> _
Public Shared Function ChangeDisplaySettings( _
ByRef lpDevMode As DEVMODE, _
ByVal dwFlags As Integer) As Integer
End Function

End
Class

Public
Class ResolutionChanger

Private Shared Function CreateDevMode() As DEVMODE
Dim dm As New DEVMODE
dm.dmDeviceName =
New String(New Char(32) {})
dm.dmFormName =
New String(New Char(32) {})
dm.dmSize =
CShort(Marshal.SizeOf(dm))
Return dm
End Function

Public Enum DisplayChangeResultCode
DISP_CHANGE_SUCCESSFUL = 0
DISP_CHANGE_RESTART = 1
DISP_CHANGE_FAILED = -1
DISP_CHANGE_BADMODE = -2
DISP_CHANGE_NOTUPDATED = -3
DISP_CHANGE_BADFLAGS = -4
DISP_CHANGE_BADPARAM = -5
DISP_CHANGE_BADDUALVIEW = -6
End Enum

Public Shared Sub ChangeResolution(ByVal width As Integer, ByVal height As Integer, ByVal freq As Integer)

Const DM_PELSWIDTH As Integer = &H80000
Const DM_PELSHEIGHT As Integer = &H100000
Const DM_DISPLAYFREQUENCY As Integer = &H400000
Const ENUM_CURRENT_SETTINGS As Integer = -1
Dim DevM As DEVMODE = CreateDevMode()
Dim enumResult As Integer
Dim changeResult As DisplayChangeResultCode

DevM.dmFields = DM_PELSWIDTH
Or DM_PELSHEIGHT Or DM_DISPLAYFREQUENCY

enumResult = NativeMethods.EnumDisplaySettings(
Nothing, ENUM_CURRENT_SETTINGS, DevM)

DevM.dmPelsWidth = width
DevM.dmPelsHeight = height
DevM.dmDisplayFrequency = freq

changeResult =
CType(NativeMethods.ChangeDisplaySettings(DevM, 0), DisplayChangeResultCode)

If changeResult <> DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL Then
Throw New Exception("Failed to change resolution: " & changeResult.ToString)
End If

End Sub

End
Class

I am using this code. and it works fine.

if you got any error, let me know.

Thank You.

Best Regards

Utkarsh Gajjar

Utkarsh  Tuesday, September 30, 2008 2:22 PM

Hi sivakl_2001

You can set the Size property of your form base on the screen resolution. Here is an FAQ. Please look at this for reference.

http://www.syncfusion.com/faq/windowsforms/search/1002.aspx

In this FAQ, you can use Screen.PrimarScreen.Bounds to get the screen resolution.

Sincerely,

Kira Qian

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Kira Qian  Thursday, October 02, 2008 4:02 AM

You can use google to search for other answers

Custom Search

More Threads

• Referenced controls dll doesn't display controls in toolbox
• Best Book for Control Development
• Adding and removing controls from a form within visual studio
• simple question on inherited forms
• Two keyboards, MDI application
• custom properties for controls
• Srollable Panel
• Controls get hidden in designer after debugging
• Windows form designer would not allow InitializeComponent to accept variables and arithmetic manipulations
• Web Browser control issue