Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WindowsVB.NET
Hi all
 
i wrote the below code in my application
 
Public Module resChanger
 
    Const ENUM_CURRENT_SETTINGS As Integer = -1
    Const CDS_UPDATEREGISTRY As Integer = &H1
    Const CDS_TEST As Long = &H2
 
    Const CCDEVICENAME As Integer = 32
    Const CCFORMNAME As Integer = 32
 
    Const DISP_CHANGE_SUCCESSFUL As Integer = 0
    Const DISP_CHANGE_RESTART As Integer = 1
    Const DISP_CHANGE_FAILED As Integer = -1
 
    Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Integer, ByVal iModeNum As Integer, ByRef lpDevMode As DEVMODE) As Integer
    Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (ByRef DEVMODE As DEVMODE, ByVal flags As Integer) As Integer
 
    <StructLayout(LayoutKind.Sequential)> Public Structure DEVMODE
        <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> 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 dmOrientation As Short
        Public dmPaperSize As Short
        Public dmPaperLength As Short
        Public dmPaperWidth As Short
        Public dmScale As Short
        Public dmCopies As Short
        Public dmDefaultSource As Short
        Public dmPrintQuality As Short
        Public dmColor As Short
        Public dmDuplex As Short
        Public dmYResolution As Short
        Public dmTTOption As Short
        Public dmCollate As Short
        <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=CCFORMNAME)> Public dmFormName As String
        Public dmUnusedPadding As Short
        Public dmBitsPerPel As Short
        Public dmPelsWidth As Integer
        Public dmPelsHeight As Integer
        Public dmDisplayFlags As Integer
        Public dmDisplayFrequency As Integer
    End Structure
 
    Public Sub changeRes(ByVal theWidth As Integer, ByVal theHeight As Integer)
 
        Dim DevM As DEVMODE
 
        DevM.dmDeviceName = New [String](New Char(32) {})
        DevM.dmFormName = New [String](New Char(32) {})
        DevM.dmSize = CShort(Marshal.SizeOf(GetType(DEVMODE)))
 

        If 0 <> EnumDisplaySettings(Nothing, ENUM_CURRENT_SETTINGS, DevM) Then
            Dim lResult As Integer
 
            DevM.dmPelsWidth = theWidth
            DevM.dmPelsHeight = theHeight
            DevM.dmPelsWidth = 1280
            DevM.dmPelsHeight = 1024
 
            lResult = ChangeDisplaySettings(DevM, CDS_TEST)
 
            If lResult = DISP_CHANGE_FAILED Then
                MsgBox("Display Change Failed.", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Screen Resolution Change Failed")
            Else
 
                lResult = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
 
                Select Case lResult
                    Case DISP_CHANGE_RESTART
                        MsgBox("You must restart your computer to apply these changes.", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Screen Resolution Has Changed")
                    Case DISP_CHANGE_SUCCESSFUL
                        MsgBox("Display Change Successful.", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Screen Resolution Successful")
                    Case Else
                        MsgBox("Display Change Failed.", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Screen Resolution Change Failed")
                End Select
            End If
        End If
    End Sub
End Module
 

Please tell me how to call it in a button click event.
 
Thank you
Posted 6-Jan-13 19:58pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

There is no such concept as "call a module". You can call a method, a property (indirectly, a getter or a setter will be called), an operator.
 
To handle a click event, use AddHandler:
http://msdn.microsoft.com/en-us/library/7taxzxka.aspx[^],
http://msdn.microsoft.com/en-us/library/6yyk8z93%28v=vs.90%29.aspx[^].
 
That was about the construct which allows for both named and anonimous handler methods and therefore the best and universal.
 
Alternatively, use handles: http://msdn.microsoft.com/en-us/library/6k46st1y%28v=vs.80%29.aspx[^].
 
—SA
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To call method defined in module,
 
in side button click event,
changeRes(567,234)'pass your own values for height width
or
resChanger.changeRes(567,234)
Happy Coding!
Smile | :)
  Permalink  
v2
Comments
Aarti Meswania at 7-Jan-13 3:00am
   
why it is down-voted?
Snehasish Nandy at 7-Jan-13 3:11am
   
I don't know what was the reason for down voting...:(
Aarti Meswania at 7-Jan-13 3:12am
   
it's okay message was not for you. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 390
1 Sergey Alexandrovich Kryukov 266
2 Shai Vashdi 220
3 OriginalGriff 153
4 Tadit Dash 135
0 Sergey Alexandrovich Kryukov 9,255
1 OriginalGriff 5,433
2 Peter Leow 4,100
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid