C# 设置屏幕亮度 Windows 7

C# setting screen brightness Windows 7(C# 设置屏幕亮度 Windows 7)
本文介绍了C# 设置屏幕亮度 Windows 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自己调整屏幕亮度.因为 Windows 让我只能在有限的范围内进行调整.我想将显示器从 0 调暗到 100% 并将其关闭/打开.如果Windows可以自动执行它应该是可能的(在:x分钟后显示暗淡/在:x分钟后关闭显示).我尝试了一些我通过谷歌找到的资源和类.但它们都不起作用.

I want ajust screen brightness by my self. Because Windows lets me only adjusting in limited range. I want dim the display from 0 to 100% and turning it off/on. It should be possible if windows can it do automatically (Dim display after: x minutes/Turn off display after: x minutes). I tried some sources and classes what I found by google. But no of them works.

你有没有试过这个,或者你能推荐我任何工作代码吗?

Have you ever tried this or can you recommend me any working code?

感谢您的回复.

推荐答案

您可以使用 WmiSetBrightness 方法:

using System.Management;
//...
static void SetBrightness(byte targetBrightness) {
    ManagementScope scope = new ManagementScope("root\WMI");
    SelectQuery query = new SelectQuery("WmiMonitorBrightnessMethods");
    using(ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query)) {
        using(ManagementObjectCollection objectCollection = searcher.Get()) {
            foreach(ManagementObject mObj in objectCollection) {
                mObj.InvokeMethod("WmiSetBrightness",
                    new Object[] { UInt32.MaxValue, targetBrightness });
                break;
            }
        }
    }
}

有关详细信息,请查看 WDDM 中的亮度控制 和 监控配置功能

For more details, please take a look at Brightness Control in WDDM and Monitor Configuration Functions

这篇关于C# 设置屏幕亮度 Windows 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)