Answers for "change brightness c#"

C#
0

change brightness c#

/// A class to control Windows screen brightness:
public static class WindowsSettingsBrightnessController
    {
        public static int Get()
        {
            var mclass = new ManagementClass("WmiMonitorBrightness");
            ManagementScope Scope = new ManagementScope(@"\\.\root\wmi");
            var instances = mclass.GetInstances();
            foreach (ManagementObject instance in instances)
            {
                return (byte)instance.GetPropertyValue("CurrentBrightness");
            }
            return 0;
        }

        public static void Set(int brightness)
        {
            var mclass = new ManagementClass("WmiMonitorBrightnessMethods");
            ManagementScope Scope = new ManagementScope(@"\\.\root\wmi");
            var instances = mclass.GetInstances();
            var args = new object[] { 1, brightness };
            foreach (ManagementObject instance in instances)
            instance.InvokeMethod("WmiSetBrightness", args);
        }
    }
/// And to use it:
public void Main(int val) {
	WindowsSettingsBrightnessController.Set(val);
}
Posted by: Guest on March-14-2021

Code answers related to "change brightness c#"

C# Answers by Framework

Browse Popular Code Answers by Language