Results 1 to 10 of 10

Thread: [2008] How to adjust screen brightness?

Hybrid View

  1. #1

    Thread Starter
    Fanatic Member sbasak's Avatar
    Join Date
    Aug 2001
    Location
    Globe Trotter
    Posts
    524

    Re: [2008] How to adjust screen brightness?

    Can anyone help me converting the C# to VB.NET?

    Code:
            static void SetBrightness(byte targetBrightness)
            {
                //define scope (namespace)
                System.Management.ManagementScope x = new System.Management.ManagementScope("root\\WMI");
    
                //define query
                System.Management.SelectQuery q = new System.Management.SelectQuery("WmiMonitorBrightnessMethods");
    
                //output current brightness
                System.Management.ManagementObjectSearcher mox = new System.Management.ManagementObjectSearcher(x, q);
    
                System.Management.ManagementObjectCollection mok = mox.Get();
    
                foreach (System.Management.ManagementObject o in mok)
                {
                    o.InvokeMethod("WmiSetBrightness", new Object[] { UInt32.MaxValue, targetBrightness }); //note the reversed order - won't work otherwise!
                    break; //only work on the first object
                }
    
                mox.Dispose();
                mok.Dispose();
            }
    My VB code looks like this - but not working Giving me error in InvokeMethod call. Second argument should be an array but I can't figure out how.

    Code:
        Public Sub SetBrightness(ByVal v As Integer)
            Dim curBrightness As Integer = 0
            Dim x As New System.Management.ManagementScope("root\WMI")
            Dim q As New System.Management.SelectQuery("WmiMonitorBrightness")
            Dim mox As New System.Management.ManagementObjectSearcher(x, q)
            Dim mok As System.Management.ManagementObjectCollection
            Dim o As System.Management.ManagementObject
            mok = mox.Get()
    
            Dim p As Byte
            p = v.Parse(Int(v))
    
            For Each o In mok
                o.InvokeMethod("WmiSetBrightness", p)
                Exit For
            Next
    
            mox.Dispose()
            mok.Dispose()
    
        End Sub
    Can't really understand how to pass the value of brightness in my Sub procedure. The C# code seem to pass as byte instead of number.
    Last edited by sbasak; Mar 15th, 2009 at 11:47 AM.
    Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
    Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width