C#SetScreenBrightnessWindows7希望能实现屏幕亮度。因为Windows只允许我在有限的范围内进行调整。我想将显示屏从0调暗到100%,然后将其关闭/打开。它应该是一个可以自动执行的窗口(Dimshowafter:xminutes/closeafter:xminutes)。我尝试了谷歌找到的一些资源和课程。但他们没有工作。你试过这个或者你能推荐我任何有效的代码吗?感谢您的答复。您可以使用WmiSetBrightness方法:usingSystem.Management;//...staticvoidSetBrightness(bytetargetBrightness){ManagementScopescope=newManagementScope("root\WMI");SelectQueryquery=newSelectQuery("WmiMonitorBrightnessMethods");using(ManagementObjectSearchersearcher=newManagementObjectSearcher(scope,query)){using(ManagementObjectCollectionobjectCollection=searcher.Get()){foreach(ManagementObjectmObjinobjectCollection){mObj.InvokeMethod("WmiSetBrightness",newObject[]{UInt32.MaxValue,目标亮度});休息;}}}}有关详细信息,请查看WDDM中的亮度控制和监视器配置函数使用System.ComponentModel;使用System.Runtime.InteropServices;命名空间MediaManagerSql.DataAccess.Sql.EntityFramework{publicclassScreenBrightness:Component{privateint_gammaValue;私人坡道_ramp;publicSc??reenBrightness(){InitializeComponent();}publicSc??reenBrightness(IContainercontainer){container.Add(this);alizeComponent();}[Description("亮度伽玛值")][类别("亮度")]publicintSetGammaValue{get{return_gammaValue;}设置{_gammaValue=值;}}[DllImport("gdi32.dll")]publicstaticexternboolSetDeviceGammaRamp(IntPtrhDC,refRAMPlpRamp);[DllImport("user32.dll")]privatestaticexternIntPtrGetDC(IntPtrhWnd);//////将选定的伽玛值应用于屏幕///publicvoidApplyGamma(){//由于伽玛值最大为44,我们需要从中获取百分比,因为//它需要从0-100%双gValue=_gammaValue;gValue=Math.Floor(Convert.ToDouble((gValue/2.27)));_gammaValue=Convert.ToInt16(gValue);如果(_gammaValue!=0){_ramp.Red=newushort[256];_ramp.Green=newushort[256];_ramp.Blue=newushort[256];for(inti=1;i使用MicrosoftAPI调整屏幕亮度调用SetDeviceGammaRamp函数。尝试这个代码。使用系统;使用System.Collections.Generic;使用System.ComponentModel;使用系统数据;使用系统绘图;使用System.Linq;使用系统文本;使用System.Threading.Tasks;使用System.Windows.Forms;使用System.Runtime.InteropServices;namespacebrightnesscontrol{publicpartialclassForm1:Form{[DllImport("gdi32.dll")]privateunsafestaticexternboolSetDeviceGammaRamp(Int32hdc,void*ramp);私人静态布尔初始化=假;私有静态Int32hdc;私有静态整数;publicForm1(){InitializeComponent();}privatestaticvoidInitializeClass(){如果(初始化)返回;hdc=Graphics.FromHwnd(IntPtr.Zero).GetHdc().ToInt32();初始化=真;}publicstaticunsafeboolSetBrightness(intbrightness){InitializeClass();如果(亮度>255)亮度=255;如果(亮度65535)arrayVal=65535;*idx=(短)arrayVal;idx++;}}boolretVal=SetDeviceGammaRamp(hdc,gArray);返回值;}私有evoidtrackBar1_Scroll(objectsender,EventArgse){}privatevoidbutton1_Click(objectsender,EventArgse){a=trackBar1.Value;设置亮度(一);}}}创建一个WindowsForms应用程序,并拖动按钮和trackbar可以在这里查看教程:http://www.lattepanda.com/topic-f11t3020.html以上就是C#学习教程的全部内容:C#设置屏幕亮度Windows7,如果对大家有用还需要了解更多C#学习教程,希望大家多多关注---本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
